- Added migration for ticket assignment and comments (`assigned_user_id` and `ticket_replies` table). - Implemented `TicketAssignedNotification` and `TicketCommentedNotification`. - Created `ReplyData`, `TicketListData`, and `PostReplyRequest` data classes. - Introduced `ResolveNotificationRouteController` for modular notification redirection. - Updated UI to support assigning users and posting comments on tickets. - User is navigated to comments page when clicked on the ticket, upon navigation ticket details modal is opened. - Extended tests to cover assignments, comments, status transitions, and notifications.
68 lines
2.3 KiB
PHP
68 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Data\Ui\Ticket;
|
|
|
|
use App\Enums\TicketStatusEnum;
|
|
use App\Models\Ticket;
|
|
use Spatie\LaravelData\Data;
|
|
|
|
final class TicketData extends Data
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $ticketId,
|
|
public int $userId,
|
|
public string $userName,
|
|
public ?int $connectedAppId,
|
|
public ?string $appName,
|
|
public string $issueCategory,
|
|
public ?string $description,
|
|
public int $statusId,
|
|
public TicketStatusEnum $status,
|
|
public array $notifiedRoleNames,
|
|
public array $notifiedUserNames,
|
|
public string $createdAt,
|
|
public array $attachments = [],
|
|
public ?int $assignedUserId = null,
|
|
public ?string $assignedUserName = null,
|
|
public array $replies = [],
|
|
) {}
|
|
|
|
public static function fromModel(Ticket $ticket): self
|
|
{
|
|
$attachments = $ticket->attachments->map(fn ($attachment) => [
|
|
'id' => $attachment->id,
|
|
'file_name' => $attachment->file_name,
|
|
'file_path' => $attachment->file_path,
|
|
'file_size' => $attachment->file_size,
|
|
'mime_type' => $attachment->mime_type,
|
|
])->toArray();
|
|
|
|
$replies = $ticket->relationLoaded('replies')
|
|
? $ticket->replies->map(fn ($reply) => ReplyData::fromModel($reply))->toArray()
|
|
: [];
|
|
|
|
return new self(
|
|
id: $ticket->id,
|
|
ticketId: $ticket->ticket_id,
|
|
userId: $ticket->user_id,
|
|
userName: $ticket->user->name,
|
|
connectedAppId: $ticket->connected_app_id,
|
|
appName: $ticket->connectedApp?->name,
|
|
issueCategory: $ticket->issue_category,
|
|
description: $ticket->description,
|
|
statusId: $ticket->status_id,
|
|
status: TicketStatusEnum::tryFrom($ticket->status->name),
|
|
notifiedRoleNames: $ticket->notifiedRoles->pluck('name')->toArray(),
|
|
notifiedUserNames: $ticket->notifiedUsers->pluck('name')->toArray(),
|
|
createdAt: $ticket->created_at->toDateTimeString(),
|
|
attachments: $attachments,
|
|
assignedUserId: $ticket->assigned_user_id,
|
|
assignedUserName: $ticket->assignedUser?->name,
|
|
replies: $replies,
|
|
);
|
|
}
|
|
}
|