fix questionnaire and profile errors format
This commit is contained in:
@ -3,22 +3,46 @@
|
||||
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 verbs(): array
|
||||
// {
|
||||
// return [
|
||||
// '' => ['get'],
|
||||
// 'profile-with-report-permission' => ['post', 'patch']
|
||||
// ];
|
||||
// }
|
||||
|
||||
public function behaviors(): array
|
||||
{
|
||||
return [
|
||||
'' => ['get'],
|
||||
'profile-with-report-permission' => ['post', 'patch']
|
||||
];
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
|
||||
'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
|
||||
{
|
||||
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;
|
||||
|
||||
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 [
|
||||
'questionnaires-list' => ['get'],
|
||||
'questionnaire-completed' => ['get'],
|
||||
];
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user