fix actionReportsByDate

This commit is contained in:
iIronside 2023-01-19 17:16:43 +03:00
parent 3e236c5869
commit 3ac2d54ec2

View File

@ -137,27 +137,19 @@ class ReportsController extends ApiController
/** /**
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionReportsByDate($fromDate, $toDate, $user_card_id = null) public function actionReportsByDate($fromDate, $toDate, $user_card_id)
{ {
if (!$this->checkDate($fromDate) || !$this->checkDate($toDate)) { if (!$this->checkDate($fromDate) || !$this->checkDate($toDate)) {
throw new BadRequestHttpException('Wrong date format'); throw new BadRequestHttpException('Wrong date format');
} }
$params = Yii::$app->request->get(); $params = Yii::$app->request->get();
$userId = $user_card_id ?? Yii::$app->user->id;
/** @var UserCard $userCard */
$userCard = UserCard::find()->where(['id_user' => $userId])->one();
if (!$userCard) {
throw new NotFoundHttpException('User not found');
}
$reportsModel = new ReportSearchForm(); $reportsModel = new ReportSearchForm();
$reportsModel->attributes = $params; $reportsModel->attributes = $params;
$reportsModel->user_card_id = $userCard->id; $reportsModel->user_card_id = $user_card_id;
$reports = $reportsModel->reportsByDate(); $reports = $reportsModel->reportsByDate();
return $reportsModel;
return ArrayHelper::toArray($reports , [ return ArrayHelper::toArray($reports , [
'common\models\Reports' => [ 'common\models\Reports' => [
'date' => 'created_at', 'date' => 'created_at',