Backend: - Add MCP Serializer to centralize entity-to-array conversion (~300 lines deduped) - Fix race condition in task/ticket number generation (SELECT FOR UPDATE + transaction) - Add unique constraint on task (project_id, number) with migration - Fix MIME type validation: use server-detected finfo instead of client-supplied type - Add allowlist of permitted MIME types for uploads - Fix TaskDocumentDownloadController: allow ROLE_CLIENT access, add priority:1 - Fix notification sent even when ticket status unchanged - Remove redundant exception constructors - Simplify services (BookStackApi double fetch, TokenEncryptor, GiteaApi) - Consolidate duplicate checks in processors Frontend: - Fix useApi isHandlingUnauthorized scope (module-level to prevent double 401 redirect) - Fix client-tickets toast key copy-paste bug - Merge duplicated tasks service methods (getByProject + getByProjectArchived) - Extract shared uploadWithRelation helper in task-documents service - Extract formatFileSize utility from duplicated component code - Extract status transition logic into useClientTicketHelpers composable - Remove dead code (unused router, handleLogout, empty script blocks) - Merge duplicate watchers and onMounted calls - Normalize arrow functions to function declarations per convention Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
47 lines
1.9 KiB
TypeScript
47 lines
1.9 KiB
TypeScript
import type { ClientTicket, ClientTicketWrite, ClientTicketStatusUpdate } from './dto/client-ticket'
|
|
import type { HydraCollection } from '~/utils/api'
|
|
import { extractHydraMembers } from '~/utils/api'
|
|
|
|
export function useClientTicketService() {
|
|
const api = useApi()
|
|
|
|
async function getAll(params?: { project?: number; status?: string; submittedBy?: number }): Promise<ClientTicket[]> {
|
|
const query: Record<string, unknown> = {}
|
|
if (params?.project) query.project = `/api/projects/${params.project}`
|
|
if (params?.status) query.status = params.status
|
|
if (params?.submittedBy) query.submittedBy = `/api/users/${params.submittedBy}`
|
|
const data = await api.get<HydraCollection<ClientTicket>>('/client_tickets', query)
|
|
return extractHydraMembers(data)
|
|
}
|
|
|
|
async function getById(id: number): Promise<ClientTicket> {
|
|
return api.get<ClientTicket>(`/client_tickets/${id}`)
|
|
}
|
|
|
|
async function create(payload: ClientTicketWrite): Promise<ClientTicket> {
|
|
return api.post<ClientTicket>('/client_tickets', payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'portal.ticketCreated',
|
|
})
|
|
}
|
|
|
|
async function updateStatus(id: number, payload: ClientTicketStatusUpdate): Promise<ClientTicket> {
|
|
return api.patch<ClientTicket>(`/client_tickets/${id}`, payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'clientTicket.statusUpdated',
|
|
})
|
|
}
|
|
|
|
async function update(id: number, data: Partial<ClientTicketWrite>): Promise<ClientTicket> {
|
|
return api.patch<ClientTicket>(`/client_tickets/${id}`, data as Record<string, unknown>, {
|
|
toastSuccessKey: 'clientTicket.updated',
|
|
})
|
|
}
|
|
|
|
async function remove(id: number): Promise<void> {
|
|
await api.delete(`/client_tickets/${id}`, {}, {
|
|
toastSuccessKey: 'clientTicket.deleted',
|
|
})
|
|
}
|
|
|
|
return { getAll, getById, create, update, updateStatus, remove }
|
|
}
|