Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SavePromptFormRequest | |
0.00% |
0 / 35 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| authorize | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| failedAuthorization | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| rules | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests\FlyAI; |
| 4 | |
| 5 | use App\Http\Models\Prompts\CustomPrompts; |
| 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 SavePromptFormRequest 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 | |
| 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:prompt_type,_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 | ]; |
| 54 | } |
| 55 | |
| 56 | return [ |
| 57 | 'template_prompt_id' => 'required|string|exists:prompt_type,_id', |
| 58 | 'name' => 'required|string', |
| 59 | 'persona_id' => 'sometimes|nullable|string|exists:user_persona,_id', |
| 60 | 'topic' => 'sometimes|nullable|string', |
| 61 | 'insert_role' => 'sometimes|nullable|string', |
| 62 | 'prompt_company_new_update_id' => 'sometimes|nullable|string|exists:prompt_company_new_update,_id', |
| 63 | 'prompt_personal_milestone_id' => 'sometimes|nullable|string|exists:prompt_personal_milestone,_id', |
| 64 | 'prompt_tone_id' => 'sometimes|nullable|string|exists:prompt_tone,_id', |
| 65 | 'prompt_language_id' => 'required|string|exists:prompt_language,_id', |
| 66 | 'length_of_post_id' => 'required|string|exists:prompt_length_of_post,_id', |
| 67 | 'youtube_url' => 'sometimes|nullable|string', |
| 68 | 'blog_url' => 'sometimes|nullable|string', |
| 69 | 'include_hashtags' => 'required|boolean', |
| 70 | 'include_emojis' => 'required|boolean', |
| 71 | 'additional_instructions' => 'sometimes|nullable|string', |
| 72 | 'feature' => 'required|string|in:flypost', |
| 73 | ]; |
| 74 | } |
| 75 | } |