Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
RewriteFormRequest | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
authorize | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
failedAuthorization | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
rules | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Http\Requests\FlyAI; |
4 | |
5 | use App\Helpers\Constants; |
6 | use App\Traits\AccountCenter\Reporting\FlyMsgAITrackingTrait; |
7 | use App\Traits\SubscriptionTrait; |
8 | use Illuminate\Auth\Access\AuthorizationException; |
9 | use Illuminate\Foundation\Http\FormRequest; |
10 | |
11 | class RewriteFormRequest extends FormRequest |
12 | { |
13 | use SubscriptionTrait, FlyMsgAITrackingTrait; |
14 | |
15 | /** |
16 | * Determine if the user is authorized to make this request. |
17 | */ |
18 | public function authorize(): bool |
19 | { |
20 | $user = $this->user(); |
21 | |
22 | $currentSubscriptionPlan = $this->getCurrentPlan($user); |
23 | $total = Constants::CURRENT_SUBSCRIPTION_PLAN_IDENTIFIERS[$currentSubscriptionPlan->identifier]; |
24 | |
25 | $used = $this->getQuotaUsed($user->id); |
26 | |
27 | return $used < $total; |
28 | } |
29 | |
30 | protected function failedAuthorization() |
31 | { |
32 | throw new AuthorizationException("You have used up your quota for the day. Please upgrade your plan."); |
33 | } |
34 | |
35 | /** |
36 | * Get the validation rules that apply to the request. |
37 | * |
38 | * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
39 | */ |
40 | public function rules(): array |
41 | { |
42 | return [ |
43 | 'action' => 'required|string|in:improve-writing,humanize,change-tone,make-shorter,make-longer,simplify,continue-writing,translate,score', |
44 | 'input' => 'required|string', |
45 | 'context' => 'sometimes|nullable|string', |
46 | 'tone' => 'sometimes|nullable|string|exists:prompt_tone,_id', |
47 | 'language' => 'sometimes|nullable|string|exists:fly_grammar_language,_id', |
48 | 'product' => 'required|string|in:sentence_rewrite,paragraph_rewrite', |
49 | ]; |
50 | } |
51 | } |