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
13    public function rules(): array
14    {
15        return [
16            'description' => 'sometimes|nullable|string',
17            'original_text' => 'sometimes|nullable|string',
18            'result_text' => 'sometimes|nullable|string',
19            'provider' => 'required|string',
20            'language' => 'sometimes|nullable|string',
21            'executed_at' => 'sometimes|nullable|string',
22        ];
23    }
24
25    public function authorize(): bool
26    {
27        $user = $this->user();
28        $plan = $this->getCurrentPlan($user);
29
30        if ($plan->flygrammar_actions === -1) {
31            return true;
32        }
33
34        $today = now();
35
36        $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();
37
38        return $plan->flygrammar_actions > $actionsPerformedToday;
39    }
40}