Files
admin-web/src/modules/inbounds/measurement/api.ts
T

127 lines
4.4 KiB
TypeScript
Raw Normal View History

2026-08-04 21:01:39 +08:00
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
import type {
InboundMeasurementDetail,
InboundMeasurementDraftSaved,
InboundMeasurementSubmitted,
2026-08-07 17:14:42 +08:00
CartonMeasurementResult,
ConfirmedPackageCountRequest,
2026-08-04 21:01:39 +08:00
SaveInboundMeasurementDraftRequest,
SubmitInboundMeasurementRequest,
UpdateMeasurementCalculationStrategyRequest,
MeasurementCalculationStrategyUpdated,
2026-09-10 11:38:38 +08:00
UpdateMeasurementOuterDimensionsRequest,
MeasurementOuterDimensionsUpdated,
2026-08-12 14:08:33 +08:00
ManualCartonScanRequest,
2026-08-04 21:01:39 +08:00
} from './types'
function measurementPath(inboundId: string) {
return `/platform/v1/first-leg/inbounds/${encodeURIComponent(inboundId)}/measurement`
}
2026-08-07 17:14:42 +08:00
export async function updateConfirmedPackageCount(
customerId: string,
inboundId: string,
itemId: string,
payload: ConfirmedPackageCountRequest,
) {
const response = await http.put<ApiEnvelope<CartonMeasurementResult>, ApiEnvelope<CartonMeasurementResult>>(
`${measurementPath(inboundId)}/items/${segment(itemId)}/confirmed-package-count`,
payload,
{ params: { tenantId: customerId } },
)
return unwrapApiResponse(response)
}
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) {
2026-08-07 17:14:42 +08:00
// Device-scanned fields expected from the backend: originalPackageCount and
2026-08-18 16:09:43 +08:00
// items[].boxCode, machineNo, deviceMeasuredAt. Keep the response aligned with the backend OpenAPI.
2026-08-04 21:01:39 +08:00
const response = await http.get<ApiEnvelope<InboundMeasurementDetail>, ApiEnvelope<InboundMeasurementDetail>>(
measurementPath(inboundId),
2026-09-04 14:31:09 +08:00
// Calculation-mode saves use a sibling PUT endpoint. A cache may otherwise keep
// returning the pre-save measurement and make a successful update look failed.
{ params: { tenantId: customerId, requestAt: Date.now() } },
2026-08-04 21:01:39 +08:00
)
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 updateMeasurementCalculationStrategy(
customerId: string,
inboundId: string,
payload: UpdateMeasurementCalculationStrategyRequest,
) {
const response = await http.put<ApiEnvelope<MeasurementCalculationStrategyUpdated>, ApiEnvelope<MeasurementCalculationStrategyUpdated>>(
`${measurementPath(inboundId)}/calculation-strategy`,
payload,
{ params: { tenantId: customerId } },
)
return unwrapApiResponse(response)
}
2026-09-10 11:38:38 +08:00
export async function updateMeasurementOuterDimensions(
customerId: string,
inboundId: string,
itemId: string,
payload: UpdateMeasurementOuterDimensionsRequest,
) {
const response = await http.put<ApiEnvelope<MeasurementOuterDimensionsUpdated>, ApiEnvelope<MeasurementOuterDimensionsUpdated>>(
`${measurementPath(inboundId)}/items/${segment(itemId)}/outer-dimensions`,
payload,
{ params: { tenantId: customerId } },
)
return unwrapApiResponse(response)
}
2026-08-04 21:01:39 +08:00
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
2026-08-12 14:08:33 +08:00
export async function createManualCartonScan(
customerId: string,
inboundId: string,
payload: ManualCartonScanRequest,
image: File,
) {
const data = new FormData()
data.append('data', new Blob([JSON.stringify(payload)], { type: 'application/json' }))
data.append('image', image)
const response = await http.post<ApiEnvelope<CartonMeasurementResult>, ApiEnvelope<CartonMeasurementResult>>(
2026-08-12 14:57:02 +08:00
`${measurementPath(inboundId)}/manual-cartons`,
2026-08-12 14:08:33 +08:00
data,
{ params: { tenantId: customerId }, headers: { 'Content-Type': 'multipart/form-data' } },
)
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' },
)
}