fix add report
This commit is contained in:
parent
ac03d43a40
commit
b6d958bdc0
@ -251,7 +251,7 @@
|
||||
`https://guild.craft-group.xyz/api/reports/create`
|
||||
|
||||
<p>
|
||||
Для того, отправить приглашение профилю на собеседование, необходимо сделать
|
||||
Для создания отчёта, необходимо сделать
|
||||
<b>POST</b> запрос на URL https://guild.craft-group.xyz/api/reports/create
|
||||
</p>
|
||||
<p>
|
||||
|
@ -2,19 +2,15 @@
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\behaviors\GsCors;
|
||||
use common\classes\Debug;
|
||||
use common\models\Reports;
|
||||
use common\models\ReportsTask;
|
||||
use common\models\UserCard;
|
||||
use frontend\modules\api\models\ReportSearchForm;
|
||||
use JsonException;
|
||||
use Yii;
|
||||
use yii\db\Expression;
|
||||
use yii\filters\auth\CompositeAuth;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\filters\ContentNegotiator;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\Response;
|
||||
@ -100,37 +96,32 @@ class ReportsController extends ApiController
|
||||
}
|
||||
|
||||
if(!isset($params['user_card_id'])){
|
||||
/** @var UserCard $userCard */
|
||||
$userCard = UserCard::find()->where(['id_user' => Yii::$app->user->id])->one();
|
||||
|
||||
if($userCard){
|
||||
$userCardId = $userCard->id;
|
||||
} else {
|
||||
throw new BadRequestHttpException('User not found!');
|
||||
$params['user_card_id'] = $userCard->id;
|
||||
}
|
||||
} else {
|
||||
$userCardId = $params['user_card_id'];
|
||||
}
|
||||
|
||||
|
||||
$reports = [];
|
||||
foreach ($params['tasks'] as $task) {
|
||||
$report = new Reports();
|
||||
$report->load($task);
|
||||
$report->difficulties = $report->difficulties ?? $params['difficulties'];
|
||||
$report->tomorrow = $report->difficulties ?? $params['tomorrow'];
|
||||
$report->today = $report->today ?? $params['today'];
|
||||
$report->user_card_id = $report->user_card_id ?? $userCardId;
|
||||
$report->created_at = date('Y-m-d');
|
||||
|
||||
if ($report->validate() && !$report->save()) {
|
||||
throw new BadRequestHttpException(json_encode($report->errors));
|
||||
$reportsModel = new Reports();
|
||||
$reportsModel->attributes = $params;
|
||||
if(!$reportsModel->validate() || !$reportsModel->save()){
|
||||
throw new BadRequestHttpException(json_encode($reportsModel->errors));
|
||||
}
|
||||
|
||||
$reports[] = $report;
|
||||
$tasks = $params['tasks'];
|
||||
foreach ($tasks as $task) {
|
||||
$reportsTask = new ReportsTask();
|
||||
$reportsTask->attributes = $task;
|
||||
$reportsTask->report_id = $reportsModel->id;
|
||||
$reportsTask->created_at = $reportsTask->created_at ?? strtotime($reportsModel->created_at);
|
||||
$reportsTask->status = $reportsTask->status ?? 1;
|
||||
|
||||
if(!$reportsTask->validate() || !$reportsTask->save()){
|
||||
throw new BadRequestHttpException(json_encode($reportsTask->errors));
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($reports);
|
||||
return array_merge($reportsModel->toArray());
|
||||
}
|
||||
|
||||
public function actionDelete()
|
||||
|
Loading…
Reference in New Issue
Block a user