Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 58 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| EngageGenerateFormRequest | |
0.00% |
0 / 58 |
|
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 / 52 |
|
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 EngageGenerateFormRequest 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 | 'is_reply' => 'required|boolean', |
| 44 | 'context' => [ |
| 45 | 'required', |
| 46 | 'array', |
| 47 | 'min:1', |
| 48 | 'context' => [ |
| 49 | 'post' => [ |
| 50 | 'required', |
| 51 | 'array', |
| 52 | 'min:1', |
| 53 | 'post' => [ |
| 54 | 'postedBy' => 'sometimes|nullable|string', |
| 55 | 'description' => 'sometimes|nullable|string', |
| 56 | 'postedTime' => 'sometimes|nullable|string', |
| 57 | 'content' => 'required|string', |
| 58 | ], |
| 59 | ], |
| 60 | 'comments' => [ |
| 61 | 'required', |
| 62 | 'array', |
| 63 | 'comments' => [ |
| 64 | 'commenterName' => 'required|string', |
| 65 | 'commenterUrl' => 'required|string', |
| 66 | 'commentText' => 'required|string', |
| 67 | 'uniqueId' => 'required|string', |
| 68 | 'isReplyingTo' => 'required|boolean', |
| 69 | 'replies' => 'sometimes|array', |
| 70 | 'replies.*' => 'required|array', |
| 71 | 'replies.*' => [ |
| 72 | 'commenterName' => 'required|string', |
| 73 | 'commenterUrl' => 'required|string', |
| 74 | 'commentText' => 'required|string', |
| 75 | 'uniqueId' => 'required|string', |
| 76 | 'isReplyingTo' => 'required|boolean', |
| 77 | 'replies' => 'sometimes|array', |
| 78 | 'replies.*' => 'required|array', |
| 79 | ], |
| 80 | ], |
| 81 | ], |
| 82 | ], |
| 83 | ], |
| 84 | 'prompt_id' => 'required|string|exists:prompt_type,_id', |
| 85 | 'custom_prompt_id' => 'sometimes|nullable|string|exists:custom_prompts,_id', |
| 86 | 'include_hashtags' => 'required|boolean', |
| 87 | 'include_emojis' => 'required|boolean', |
| 88 | 'is_regenerate' => 'sometimes|boolean', |
| 89 | 'uniqueId' => 'sometimes|nullable|string', |
| 90 | 'persona_id' => 'sometimes|nullable|string|exists:user_persona,_id', |
| 91 | 'prompt_tone_id' => 'sometimes|nullable|string|exists:prompt_tone,_id', |
| 92 | 'additional_instructions' => 'sometimes|nullable|string', |
| 93 | ]; |
| 94 | } |
| 95 | } |