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