fix questionnaire and profile errors format
This commit is contained in:
parent
866389a95a
commit
6385787702
@ -16,11 +16,11 @@ class ProfileService
|
|||||||
/**
|
/**
|
||||||
* @throws ServerErrorHttpException
|
* @throws ServerErrorHttpException
|
||||||
*/
|
*/
|
||||||
public static function getMainData($user_id)//: array
|
public static function getMainData($user_id): array
|
||||||
{
|
{
|
||||||
$userCard = UserCard::findOne(['id_user' => $user_id]);
|
$userCard = UserCard::findOne(['id_user' => $user_id]);
|
||||||
if (empty($userCard)) {
|
if (empty($userCard)) {
|
||||||
throw new ServerErrorHttpException(json_encode('Profile not found!'));
|
throw new ServerErrorHttpException('Profile not found!');
|
||||||
}
|
}
|
||||||
return array('fio' => $userCard->fio,
|
return array('fio' => $userCard->fio,
|
||||||
'photo' => $userCard->photo,
|
'photo' => $userCard->photo,
|
||||||
@ -31,10 +31,7 @@ class ProfileService
|
|||||||
'position_name' => $userCard->position->name);
|
'position_name' => $userCard->position->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function getProfile($id, $request): ?array
|
||||||
* @throws BadRequestHttpException
|
|
||||||
*/
|
|
||||||
public static function getProfile($id, $request)//: ?array
|
|
||||||
{
|
{
|
||||||
$searchModel = new ProfileSearchForm();
|
$searchModel = new ProfileSearchForm();
|
||||||
$searchModel->attributes = $request;
|
$searchModel->attributes = $request;
|
||||||
@ -46,7 +43,7 @@ class ProfileService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws BadRequestHttpException
|
* @throws ServerErrorHttpException
|
||||||
*/
|
*/
|
||||||
public static function getProfileWithReportPermission($user_card_id): ?array
|
public static function getProfileWithReportPermission($user_card_id): ?array
|
||||||
{
|
{
|
||||||
@ -59,7 +56,7 @@ class ProfileService
|
|||||||
self::addPermission($profile, $user_card_id);
|
self::addPermission($profile, $user_card_id);
|
||||||
return $profile;
|
return $profile;
|
||||||
}
|
}
|
||||||
throw new BadRequestHttpException(json_encode('There is no user with this id'));
|
throw new ServerErrorHttpException('There is no user with this id');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function addPermission(&$profile, $user_card_id)
|
private static function addPermission(&$profile, $user_card_id)
|
||||||
|
@ -51,7 +51,7 @@ class UserQuestionnaireService
|
|||||||
{
|
{
|
||||||
$userQuestionnaireModel = UserQuestionnaire::findOne(['uuid' => $user_questionnaire_uuid]);
|
$userQuestionnaireModel = UserQuestionnaire::findOne(['uuid' => $user_questionnaire_uuid]);
|
||||||
if (empty($userQuestionnaireModel)) {
|
if (empty($userQuestionnaireModel)) {
|
||||||
throw new ServerErrorHttpException(json_encode('Not found UserQuestionnaire'));
|
throw new ServerErrorHttpException('Not found UserQuestionnaire');
|
||||||
}
|
}
|
||||||
$count = Question::find()
|
$count = Question::find()
|
||||||
->where(['questionnaire_id' => $userQuestionnaireModel->questionnaire_id])
|
->where(['questionnaire_id' => $userQuestionnaireModel->questionnaire_id])
|
||||||
@ -67,7 +67,7 @@ class UserQuestionnaireService
|
|||||||
{
|
{
|
||||||
$userQuestionnaireModel = UserQuestionnaire::findOne(['uuid' => $user_questionnaire_uuid]);
|
$userQuestionnaireModel = UserQuestionnaire::findOne(['uuid' => $user_questionnaire_uuid]);
|
||||||
if (empty($userQuestionnaireModel)) {
|
if (empty($userQuestionnaireModel)) {
|
||||||
throw new ServerErrorHttpException(json_encode('Not found UserQuestionnaire'));
|
throw new ServerErrorHttpException('Not found UserQuestionnaire');
|
||||||
}
|
}
|
||||||
$pointSum = Question::find()
|
$pointSum = Question::find()
|
||||||
->where(['questionnaire_id' => $userQuestionnaireModel->questionnaire_id])
|
->where(['questionnaire_id' => $userQuestionnaireModel->questionnaire_id])
|
||||||
|
@ -3,22 +3,46 @@
|
|||||||
namespace frontend\modules\api\controllers;
|
namespace frontend\modules\api\controllers;
|
||||||
|
|
||||||
use common\services\ProfileService;
|
use common\services\ProfileService;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
use yii\web\BadRequestHttpException;
|
use yii\web\BadRequestHttpException;
|
||||||
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\web\ServerErrorHttpException;
|
use yii\web\ServerErrorHttpException;
|
||||||
|
|
||||||
class ProfileController extends ApiController
|
class ProfileController extends ApiController
|
||||||
{
|
{
|
||||||
public function verbs(): array
|
// public function verbs(): array
|
||||||
|
// {
|
||||||
|
// return [
|
||||||
|
// '' => ['get'],
|
||||||
|
// 'profile-with-report-permission' => ['post', 'patch']
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function behaviors(): array
|
||||||
{
|
{
|
||||||
return [
|
return ArrayHelper::merge(parent::behaviors(), [
|
||||||
'' => ['get'],
|
|
||||||
'profile-with-report-permission' => ['post', 'patch']
|
'verbs' => [
|
||||||
];
|
'class' => \yii\filters\VerbFilter::class,
|
||||||
|
'actions' => [
|
||||||
|
'' => ['get'],
|
||||||
|
'profile-with-report-permission' => ['post', 'patch'],
|
||||||
|
'get-main-data' => ['get']
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws NotFoundHttpException
|
||||||
|
*/
|
||||||
public function actionIndex($id = null): ?array
|
public function actionIndex($id = null): ?array
|
||||||
{
|
{
|
||||||
return ProfileService::getProfile($id, \Yii::$app->request->get());
|
$profiles = ProfileService::getProfile($id, \Yii::$app->request->get());
|
||||||
|
if(empty($profiles)) {
|
||||||
|
throw new NotFoundHttpException('Profiles not found');
|
||||||
|
}
|
||||||
|
return $profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,17 +3,27 @@
|
|||||||
namespace frontend\modules\api\controllers;
|
namespace frontend\modules\api\controllers;
|
||||||
|
|
||||||
use common\services\UserQuestionnaireService;
|
use common\services\UserQuestionnaireService;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\web\ServerErrorHttpException;
|
use yii\web\ServerErrorHttpException;
|
||||||
|
|
||||||
class UserQuestionnaireController extends ApiController
|
class UserQuestionnaireController extends ApiController
|
||||||
{
|
{
|
||||||
public function verbs()
|
|
||||||
|
public function behaviors(): array
|
||||||
{
|
{
|
||||||
return [
|
return ArrayHelper::merge(parent::behaviors(), [
|
||||||
'questionnaires-list' => ['get'],
|
|
||||||
'questionnaire-completed' => ['get'],
|
'verbs' => [
|
||||||
];
|
'class' => \yii\filters\VerbFilter::class,
|
||||||
|
'actions' => [
|
||||||
|
'questionnaires-list' => ['get'],
|
||||||
|
'questionnaire-completed' => ['get'],
|
||||||
|
'get-points-number' => ['get'],
|
||||||
|
'get-question-number' => ['get'],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +49,7 @@ class UserQuestionnaireController extends ApiController
|
|||||||
{
|
{
|
||||||
$userQuestionnaireModel = UserQuestionnaireService::calculateScore($user_questionnaire_uuid);
|
$userQuestionnaireModel = UserQuestionnaireService::calculateScore($user_questionnaire_uuid);
|
||||||
if ($userQuestionnaireModel->errors) {
|
if ($userQuestionnaireModel->errors) {
|
||||||
throw new ServerErrorHttpException(json_encode($userQuestionnaireModel->errors));
|
throw new ServerErrorHttpException($userQuestionnaireModel->errors);
|
||||||
}
|
}
|
||||||
return $userQuestionnaireModel;
|
return $userQuestionnaireModel;
|
||||||
}
|
}
|
||||||
@ -51,7 +61,7 @@ class UserQuestionnaireController extends ApiController
|
|||||||
{
|
{
|
||||||
$questionPointsNumber = UserQuestionnaireService::getPointsNumber($user_questionnaire_uuid);
|
$questionPointsNumber = UserQuestionnaireService::getPointsNumber($user_questionnaire_uuid);
|
||||||
if (empty($questionPointsNumber)) {
|
if (empty($questionPointsNumber)) {
|
||||||
throw new ServerErrorHttpException(json_encode('Question points not found!'));
|
throw new ServerErrorHttpException('Question points not found!');
|
||||||
}
|
}
|
||||||
return $questionPointsNumber;
|
return $questionPointsNumber;
|
||||||
}
|
}
|
||||||
@ -63,7 +73,7 @@ class UserQuestionnaireController extends ApiController
|
|||||||
{
|
{
|
||||||
$questionNumber = UserQuestionnaireService::getQuestionNumber($user_questionnaire_uuid);
|
$questionNumber = UserQuestionnaireService::getQuestionNumber($user_questionnaire_uuid);
|
||||||
if (empty($questionNumber)) {
|
if (empty($questionNumber)) {
|
||||||
throw new ServerErrorHttpException(json_encode('Question number not found!'));
|
throw new ServerErrorHttpException('Question number not found!');
|
||||||
}
|
}
|
||||||
return $questionNumber;
|
return $questionNumber;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ class ProfileSearchForm extends Model
|
|||||||
$model->andWhere(['status' => [4, 12]]);
|
$model->andWhere(['status' => [4, 12]]);
|
||||||
$model->andWhere(['deleted_at' => null]);
|
$model->andWhere(['deleted_at' => null]);
|
||||||
|
|
||||||
$model->groupBy('card_skill.card_id');
|
//$model->groupBy('card_skill.card_id');
|
||||||
|
|
||||||
$res = $model->limit($this->limit)
|
$res = $model->limit($this->limit)
|
||||||
->offset($this->offset)->orderBy('updated_at DESC')->asArray()->all();
|
->offset($this->offset)->orderBy('updated_at DESC')->asArray()->all();
|
||||||
|
Loading…
Reference in New Issue
Block a user