Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
TrackingFlyGrammarFormRequest
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 rules
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 authorize
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace App\Http\Requests;
4
5use App\Http\Models\FlyGrammarActions;
6use App\Traits\SubscriptionTrait;
7use Illuminate\Foundation\Http\FormRequest;
8
9class TrackingFlyGrammarFormRequest extends FormRequest
10{
11    use SubscriptionTrait;
12    public function rules(): array
13    {
14        return [
15            'description' => 'sometimes|nullable|string',
16            'original_text' => 'sometimes|nullable|string',
17            'result_text' => 'sometimes|nullable|string',
18            'provider' => 'required|string',
19            'language' => 'sometimes|nullable|string',
20            'executed_at' => 'sometimes|nullable|string',
21        ];
22    }
23
24    public function authorize(): bool
25    {
26        $user = $this->user();
27        $plan = $this->getCurrentPlan($user);
28
29        if ($plan->flygrammar_actions === -1) {
30            return true;
31        }
32
33        $today = now();
34
35        $actionsPerformedToday = FlyGrammarActions::where('user_id', $user->id)->where('created_at', '>=', new \MongoDB\BSON\UTCDateTime(strtotime($today->startOfDay()->toDateTimeString()) * 1000))->where('created_at', '<=', new \MongoDB\BSON\UTCDateTime(strtotime($today->endOfDay()->toDateTimeString()) * 1000))->count();
36
37        return $plan->flygrammar_actions > $actionsPerformedToday;
38    }
39}