Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.97% |
32 / 33 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| RolePlayConversationAdminResource | |
96.97% |
32 / 33 |
|
0.00% |
0 / 1 |
8 | |
0.00% |
0 / 1 |
| toArray | |
96.97% |
32 / 33 |
|
0.00% |
0 / 1 |
8 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resources\v2; |
| 4 | |
| 5 | use Illuminate\Http\Resources\Json\JsonResource; |
| 6 | |
| 7 | /** |
| 8 | * Transforms a {@see \App\Http\Models\RolePlayConversations} for admin |
| 9 | * consumption: includes the user snapshot (for display in the session |
| 10 | * browser) and the transcript + feedback payload, while still honoring the |
| 11 | * platform's `result`-wrapper + Unix timestamp conventions. |
| 12 | * |
| 13 | * @property string $_id |
| 14 | * @property string $user_id |
| 15 | * @property string|null $project_id |
| 16 | * @property string|null $company_project_id |
| 17 | * @property string|null $company_id |
| 18 | * @property string $status |
| 19 | * @property string|null $vapi_call_id |
| 20 | * @property string|null $transcript |
| 21 | * @property int|null $duration |
| 22 | * @property float|null $score |
| 23 | * @property array|null $feedback |
| 24 | * @property string|array|null $icp |
| 25 | * @property array|null $agent |
| 26 | * @property \Illuminate\Support\Carbon|null $created_at |
| 27 | * @property \Illuminate\Support\Carbon|null $updated_at |
| 28 | * @property-read \App\Http\Models\Auth\User|null $user |
| 29 | */ |
| 30 | class RolePlayConversationAdminResource extends JsonResource |
| 31 | { |
| 32 | /** |
| 33 | * @return array<string, mixed> |
| 34 | */ |
| 35 | public function toArray($request): array |
| 36 | { |
| 37 | $icp = $this->icp; |
| 38 | if (is_string($icp)) { |
| 39 | $icp = json_decode($icp, true) ?: []; |
| 40 | } |
| 41 | |
| 42 | $agent = $this->agent; |
| 43 | if (is_string($agent)) { |
| 44 | $agent = json_decode($agent, true) ?: []; |
| 45 | } |
| 46 | |
| 47 | return [ |
| 48 | 'id' => (string) $this->_id, |
| 49 | 'user_id' => $this->user_id, |
| 50 | 'project_id' => $this->project_id, |
| 51 | 'company_project_id' => $this->company_project_id, |
| 52 | 'company_id' => $this->company_id, |
| 53 | 'status' => $this->status, |
| 54 | 'vapi_call_id' => $this->vapi_call_id, |
| 55 | 'transcript' => $this->transcript, |
| 56 | 'duration' => $this->duration, |
| 57 | 'score' => $this->score !== null ? (float) $this->score : null, |
| 58 | 'feedback' => $this->feedback, |
| 59 | 'icp' => $icp, |
| 60 | 'agent' => $agent, |
| 61 | 'user' => $this->whenLoaded('user', function () { |
| 62 | if (! $this->user) { |
| 63 | return null; |
| 64 | } |
| 65 | |
| 66 | return [ |
| 67 | 'id' => (string) $this->user->id, |
| 68 | 'name' => trim(($this->user->first_name ?? '').' '.($this->user->last_name ?? '')) ?: null, |
| 69 | 'email' => $this->user->email ?? null, |
| 70 | 'company_group_id' => $this->user->company_group_id ?? null, |
| 71 | ]; |
| 72 | }), |
| 73 | 'created_at' => $this->created_at?->timestamp, |
| 74 | 'updated_at' => $this->updated_at?->timestamp, |
| 75 | ]; |
| 76 | } |
| 77 | } |