Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PostGenerateFormRequest | |
0.00% |
0 / 25 |
|
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 / 19 |
|
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 PostGenerateFormRequest 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 | 'prompt_id' => 'required|string|exists:prompt_type,_id', |
44 | 'custom_prompt_id' => 'sometimes|nullable|string|exists:custom_prompts,_id', |
45 | 'persona_id' => 'sometimes|nullable|string|exists:user_persona,_id', |
46 | 'topic' => 'sometimes|nullable|string', |
47 | 'insert_role' => 'sometimes|nullable|string', |
48 | 'prompt_company_new_update_id' => 'sometimes|nullable|string|exists:prompt_company_new_update,_id', |
49 | 'prompt_personal_milestone_id' => 'sometimes|nullable|string|exists:prompt_personal_milestone,_id', |
50 | 'prompt_tone_id' => 'sometimes|nullable|string|exists:prompt_tone,_id', |
51 | 'prompt_language_id' => 'required|string|exists:prompt_language,_id', |
52 | 'length_of_post_id' => 'required|string|exists:prompt_length_of_post,_id', |
53 | 'youtube_url' => 'sometimes|nullable|string', |
54 | 'blog_url' => 'sometimes|nullable|string', |
55 | 'include_hashtags' => 'required|boolean', |
56 | 'include_emojis' => 'required|boolean', |
57 | 'additional_instructions' => 'sometimes|nullable|string', |
58 | 'is_regenerate' => 'sometimes|boolean', |
59 | 'uniqueId' => 'sometimes|nullable|string', |
60 | ]; |
61 | } |
62 | } |