Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
SavePromptFormRequest
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 authorize
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 failedAuthorization
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 rules
100.00% covered (success)
100.00%
32 / 32
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Http\Requests\FlyAI;
4
5use App\Http\Models\Prompts\CustomPrompts;
6use App\Traits\AccountCenter\Reporting\FlyMsgAITrackingTrait;
7use App\Traits\SubscriptionTrait;
8use Illuminate\Auth\Access\AuthorizationException;
9use Illuminate\Foundation\Http\FormRequest;
10
11class SavePromptFormRequest extends FormRequest
12{
13    use FlyMsgAITrackingTrait, SubscriptionTrait;
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
24        $used = CustomPrompts::where('user_id', $user->id)->count();
25
26        return $used < $currentSubscriptionPlan->user_custom_prompts;
27    }
28
29    protected function failedAuthorization()
30    {
31        throw new AuthorizationException('Limit exceeded on your current subscription plan.');
32    }
33
34    /**
35     * Get the validation rules that apply to the request.
36     *
37     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
38     */
39    public function rules(): array
40    {
41        $feature = $this->feature;
42
43        if ($feature == 'flyengage') {
44            return [
45                'template_prompt_id' => 'required|string|exists:ai_prompts,_id',
46                'name' => 'required|string',
47                'include_hashtags' => 'required|boolean',
48                'include_emojis' => 'required|boolean',
49                'persona_id' => 'sometimes|nullable|string|exists:user_persona,_id',
50                'prompt_tone_id' => 'required|string|exists:prompt_tone,_id',
51                'additional_instructions' => 'sometimes|nullable|string',
52                'feature' => 'required|string|in:flyengage',
53                'quick_insert' => 'sometimes|boolean',
54            ];
55        }
56
57        return [
58            'template_prompt_id' => 'required|string|exists:ai_prompts,_id',
59            'name' => 'required|string',
60            'persona_id' => 'sometimes|nullable|string|exists:user_persona,_id',
61            'topic' => 'sometimes|nullable|string',
62            'insert_role' => 'sometimes|nullable|string',
63            'prompt_company_new_update_id' => 'sometimes|nullable|string|exists:prompt_company_new_update,_id',
64            'prompt_personal_milestone_id' => 'sometimes|nullable|string|exists:prompt_personal_milestone,_id',
65            'prompt_tone_id' => 'sometimes|nullable|string|exists:prompt_tone,_id',
66            'prompt_language_id' => 'required|string|exists:prompt_language,_id',
67            'length_of_post_id' => 'required|string|exists:prompt_length_of_post,_id',
68            'youtube_url' => 'sometimes|nullable|string',
69            'blog_url' => 'sometimes|nullable|string',
70            'include_hashtags' => 'required|boolean',
71            'include_emojis' => 'required|boolean',
72            'additional_instructions' => 'sometimes|nullable|string',
73            'feature' => 'required|string|in:flypost',
74            'quick_insert' => 'sometimes|boolean',
75        ];
76    }
77}