This commit is contained in:
2026-08-08 15:57:07 +08:00
parent bbb408d7b1
commit 8771cef76b
4 changed files with 65 additions and 9 deletions
@@ -4,6 +4,8 @@ import type {
TruckAppointmentPage,
TruckAppointmentQuery,
TruckAppointmentResource,
TruckAppointmentStatusHistory,
TruckAttachmentReference,
} from '../types'
const basePath = '/platform/v1/truck-appointments'
@@ -52,6 +54,27 @@ export async function getTruckAppointment(id: string | number) {
return normalizeResource(unwrapApiResponse(response))
}
export async function listTruckAppointmentHistory(id: string | number) {
const response = await http.get<ApiEnvelope<TruckAppointmentStatusHistory[] | { records?: TruckAppointmentStatusHistory[] }>, ApiEnvelope<TruckAppointmentStatusHistory[] | { records?: TruckAppointmentStatusHistory[] }>>(`${basePath}/${id}/history`)
const payload = unwrapApiResponse(response)
const records = Array.isArray(payload) ? payload : payload?.records || []
return records.map((item) => ({ ...item, id: item.id == null ? item.id : String(item.id), operatorId: item.operatorId == null ? item.operatorId : String(item.operatorId) }))
}
export async function listTruckAppointmentAttachments(id: string | number) {
const response = await http.get<ApiEnvelope<TruckAttachmentReference[]>, ApiEnvelope<TruckAttachmentReference[]>>(`${basePath}/${id}/attachments`)
return unwrapApiResponse(response).map((item) => ({ ...item, id: item.id == null ? item.id : String(item.id), fileId: String(item.fileId), uploadedBy: item.uploadedBy == null ? item.uploadedBy : String(item.uploadedBy) }))
}
export async function referenceTruckAppointmentAttachment(id: string | number, payload: { fileId: string; attachmentType?: string | null; fileName?: string | null; fileHash?: string | null }) {
const response = await http.post<ApiEnvelope<TruckAttachmentReference>, ApiEnvelope<TruckAttachmentReference>>(`${basePath}/${id}/attachments`, { ...payload, fileId: Number(payload.fileId) })
return unwrapApiResponse(response)
}
export async function deleteTruckAppointmentAttachment(id: string | number, attachmentId: string | number) {
await http.delete<ApiEnvelope<unknown>, ApiEnvelope<unknown>>(`${basePath}/${id}/attachments/${attachmentId}`)
}
export async function createTruckAppointment(payload: SaveTruckAppointmentRequest) {
const response = await http.post<ApiEnvelope<TruckAppointmentResource>, ApiEnvelope<TruckAppointmentResource>>(basePath, dtoPayload(payload))
return normalizeResource(unwrapApiResponse(response))