This commit is contained in:
2026-09-01 15:43:19 +08:00
parent 0b676ddb74
commit c59608ff2c
5 changed files with 172 additions and 43 deletions
@@ -6,6 +6,9 @@ import type {
TruckAppointmentQuery,
TruckAppointmentResource,
TruckAppointmentActionRequest,
TruckAppointmentCandidate,
TruckAppointmentCandidatePage,
TruckAppointmentCandidateQuery,
TruckAppointmentStatusHistory,
TruckAttachmentReference,
TruckAttachmentType,
@@ -60,6 +63,41 @@ export async function listTruckAppointments(query: TruckAppointmentQuery = {}) {
return normalizePage(unwrapApiResponse(response))
}
type CandidatePagePayload = Omit<TruckAppointmentCandidatePage, 'records' | 'page' | 'size' | 'total' | 'pages'> & {
records?: Array<TruckAppointmentCandidate & Record<string, unknown>>
page: number | string
size: number | string
total: number | string
pages?: number | string
}
function normalizeCandidate(candidate: TruckAppointmentCandidate & Record<string, unknown>): TruckAppointmentCandidate {
const normalized = { ...candidate } as Record<string, unknown>
for (const key of ['oceanBookingId', 'warehouseId', 'requirementId', 'containerBookingId', 'loadingPlanId']) {
if (normalized[key] !== null && normalized[key] !== undefined) normalized[key] = String(normalized[key])
}
normalized.requirementQuantity = Number(normalized.requirementQuantity || 0)
normalized.bookingDocumentReady = normalized.bookingDocumentReady === true
return normalized as unknown as TruckAppointmentCandidate
}
export async function listTruckAppointmentCandidates(query: TruckAppointmentCandidateQuery = {}) {
const response = await http.get<ApiEnvelope<CandidatePagePayload>, ApiEnvelope<CandidatePagePayload>>(`${basePath}/candidates`, {
params: { keyword: query.keyword?.trim() || undefined, page: query.page || 1, size: query.size || 200 },
})
const payload = unwrapApiResponse(response)
const page = Number(payload.page || 1)
const size = Number(payload.size || 200)
const total = Number(payload.total || 0)
return {
records: (payload.records || []).map(normalizeCandidate),
page,
size,
total,
pages: Number(payload.pages || Math.max(Math.ceil(total / size), 1)),
} satisfies TruckAppointmentCandidatePage
}
export async function getTruckAppointment(id: string | number) {
const response = await http.get<ApiEnvelope<TruckAppointmentResource>, ApiEnvelope<TruckAppointmentResource>>(`${basePath}/${id}`)
return normalizeResource(unwrapApiResponse(response))