2026-08-04 21:01:39 +08:00
|
|
|
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
|
|
|
|
import type {
|
|
|
|
|
InboundMeasurementDetail,
|
|
|
|
|
InboundMeasurementDraftSaved,
|
|
|
|
|
InboundMeasurementSubmitted,
|
|
|
|
|
SaveInboundMeasurementDraftRequest,
|
|
|
|
|
SubmitInboundMeasurementRequest,
|
|
|
|
|
} from './types'
|
|
|
|
|
|
|
|
|
|
function measurementPath(inboundId: string) {
|
|
|
|
|
return `/platform/v1/first-leg/inbounds/${encodeURIComponent(inboundId)}/measurement`
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-07 15:53:58 +08:00
|
|
|
function segment(value: string) {
|
|
|
|
|
return encodeURIComponent(value)
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-04 21:01:39 +08:00
|
|
|
export async function getInboundMeasurement(customerId: string, inboundId: string) {
|
|
|
|
|
const response = await http.get<ApiEnvelope<InboundMeasurementDetail>, ApiEnvelope<InboundMeasurementDetail>>(
|
|
|
|
|
measurementPath(inboundId),
|
|
|
|
|
{ params: { tenantId: customerId } },
|
|
|
|
|
)
|
|
|
|
|
return unwrapApiResponse(response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function saveInboundMeasurementDraft(
|
|
|
|
|
customerId: string,
|
|
|
|
|
inboundId: string,
|
|
|
|
|
payload: SaveInboundMeasurementDraftRequest,
|
|
|
|
|
) {
|
|
|
|
|
const response = await http.put<ApiEnvelope<InboundMeasurementDraftSaved>, ApiEnvelope<InboundMeasurementDraftSaved>>(
|
|
|
|
|
`${measurementPath(inboundId)}/draft`,
|
|
|
|
|
payload,
|
|
|
|
|
{ params: { tenantId: customerId } },
|
|
|
|
|
)
|
|
|
|
|
return unwrapApiResponse(response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function submitInboundMeasurement(
|
|
|
|
|
customerId: string,
|
|
|
|
|
inboundId: string,
|
|
|
|
|
payload: SubmitInboundMeasurementRequest,
|
|
|
|
|
) {
|
|
|
|
|
const response = await http.post<ApiEnvelope<InboundMeasurementSubmitted>, ApiEnvelope<InboundMeasurementSubmitted>>(
|
|
|
|
|
`${measurementPath(inboundId)}/submit`,
|
|
|
|
|
payload,
|
|
|
|
|
{ params: { tenantId: customerId } },
|
|
|
|
|
)
|
|
|
|
|
return unwrapApiResponse(response)
|
|
|
|
|
}
|
2026-08-07 15:53:58 +08:00
|
|
|
|
|
|
|
|
export function downloadInboundMeasurementImage(customerId: string, inboundId: string, fileId: string) {
|
|
|
|
|
return http.get<Blob, Blob>(
|
|
|
|
|
`/platform/v1/files/measurements/${segment(customerId)}/${segment(inboundId)}/${segment(fileId)}`,
|
|
|
|
|
{ responseType: 'blob' },
|
|
|
|
|
)
|
|
|
|
|
}
|