Files
admin-web/src/modules/overseas-warehouse/api/pallets.ts
T

95 lines
3.8 KiB
TypeScript

import { overseasHttp } from '@/shared/api/overseasHttp'
import { unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'
import { normalizeOverseasPage, type OverseasPagePayload } from './lastMileOrders'
export interface ReceivingOverseasWarehouseDto {
id: string
customerId: string
warehouseCode: string
warehouseName: string
warehouseType: string
status: string
}
export interface PalletDto {
id: string
customerId: string
warehouseId: string
locationId?: string | null
palletCode: string
palletType: string
fbaWarehouseCode: string
capacityCbm: number
unitPrice: number
status: string
remark?: string | null
version: number
createdAt?: string | null
updatedAt?: string | null
}
export interface SavePalletPayload {
palletCode: string
palletType: string
fbaWarehouseCode: string
capacityCbm: number
unitPrice: number
status: string
locationId?: string | null
remark?: string | null
}
export interface UpdatePalletPayload extends SavePalletPayload {
version: number
}
export interface PalletSummaryDto { totalCount: number; idleCount: number; occupiedCount: number; scrappedCount: number }
export async function listReceivingOverseasWarehouses() {
const records: ReceivingOverseasWarehouseDto[] = (await listSharedReceivingOverseasWarehouseOptions()).map((warehouse) => ({
id: warehouse.id,
customerId: '0',
warehouseCode: warehouse.warehouseCode,
warehouseName: warehouse.warehouseName,
warehouseType: 'OVERSEAS',
status: 'ACTIVE',
}))
return { records, page: 1, size: 200, total: records.length, pages: records.length ? 1 : 0 }
}
export async function listPallets(warehouseId: string | undefined, query: { page: number; size: number; keyword?: string; palletType?: string; status?: string }) {
const response = await overseasHttp.get<ApiEnvelope<OverseasPagePayload<PalletDto>>, ApiEnvelope<OverseasPagePayload<PalletDto>>>(
warehouseId ? `/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets` : '/platform/v1/warehouse-admin/pallets',
{ params: { ...query } },
)
return normalizeOverseasPage(unwrapApiResponse(response))
}
export async function getPalletSummary(warehouseId: string, query: { keyword?: string; palletType?: string }) {
const path = warehouseId ? `/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets/summary` : '/platform/v1/warehouse-admin/pallets/summary'
const response = await overseasHttp.get<ApiEnvelope<PalletSummaryDto>, ApiEnvelope<PalletSummaryDto>>(path, { params: { page: 1, size: 1, ...query } })
const value = unwrapApiResponse(response); return { totalCount: Number(value.totalCount), idleCount: Number(value.idleCount), occupiedCount: Number(value.occupiedCount), scrappedCount: Number(value.scrappedCount) }
}
export async function getPallet(warehouseId: string, palletId: string) {
const response = await overseasHttp.get<ApiEnvelope<PalletDto>, ApiEnvelope<PalletDto>>(
`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets/${encodeURIComponent(palletId)}`,
{},
)
return unwrapApiResponse(response)
}
export async function createPallet(warehouseId: string, payload: SavePalletPayload) {
const response = await overseasHttp.post<ApiEnvelope<string>, ApiEnvelope<string>>(
`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets`, payload,
)
return unwrapApiResponse(response)
}
export async function updatePallet(warehouseId: string, palletId: string, payload: UpdatePalletPayload) {
const response = await overseasHttp.put<ApiEnvelope<null>, ApiEnvelope<null>>(
`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets/${encodeURIComponent(palletId)}`,
payload,
)
return unwrapApiResponse(response)
}