This commit is contained in:
2026-08-06 15:32:02 +08:00
parent 9e7e1afac8
commit 33a0c48b78
22 changed files with 685 additions and 402 deletions
@@ -47,23 +47,22 @@ describe('platform location API', () => {
await expect(listPlatformLocations({
page: 2,
size: 20,
tenantId: '9223372036854775806',
warehouseId: '190000000000000101',
zoneCode: ' A ',
locationCode: ' A1 ',
locationType: 'SHELF',
status: 'AVAILABLE',
})).resolves.toEqual({ records: [], page: 2, size: 20, total: 21, pages: 2 })
await expect(getPlatformLocation('9223372036854775806', '190000000000000101', '19001')).resolves.toEqual(detail)
await expect(getPlatformLocation('190000000000000101', '19001')).resolves.toEqual(detail)
expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/locations', {
params: {
tenantId: '9223372036854775806', page: 2, size: 20, warehouseId: '190000000000000101',
page: 2, size: 20, warehouseId: '190000000000000101',
zoneCode: 'A', locationCode: 'A1', locationType: 'SHELF', status: 'AVAILABLE',
},
})
expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/locations/19001', {
params: { tenantId: '9223372036854775806', warehouseId: '190000000000000101' },
params: { tenantId: 0, warehouseId: '190000000000000101' },
})
})
@@ -74,7 +73,6 @@ describe('platform location API', () => {
await expect(listPlatformLocations({
page: 1,
size: 20,
tenantId: '',
warehouseId: '',
zoneCode: '',
locationCode: '',
@@ -93,20 +91,20 @@ describe('platform location API', () => {
vi.mocked(http.patch).mockResolvedValue({ code: '200', message: 'success', data: null })
vi.mocked(http.delete).mockResolvedValue({ code: '200', message: 'success', data: null })
await expect(createPlatformLocation(10001, payload)).resolves.toBe('19001')
await expect(updatePlatformLocation(10001, payload.warehouseId, '19001', payload)).resolves.toBeNull()
await expect(changePlatformLocationStatus(10001, payload.warehouseId, '19001', 'DISABLED', 3)).resolves.toBeNull()
await expect(deletePlatformLocation(10001, payload.warehouseId, '19001', 4)).resolves.toBeNull()
await expect(createPlatformLocation(payload)).resolves.toBe('19001')
await expect(updatePlatformLocation(payload.warehouseId, '19001', payload)).resolves.toBeNull()
await expect(changePlatformLocationStatus(payload.warehouseId, '19001', 'DISABLED', 3)).resolves.toBeNull()
await expect(deletePlatformLocation(payload.warehouseId, '19001', 4)).resolves.toBeNull()
expect(http.post).toHaveBeenCalledWith('/platform/v1/locations', payload, { params: { tenantId: 10001 } })
expect(http.post).toHaveBeenCalledWith('/platform/v1/locations', payload, { params: { tenantId: 0 } })
expect(http.put).toHaveBeenCalledWith('/platform/v1/locations/19001', payload, {
params: { tenantId: 10001, warehouseId: payload.warehouseId },
params: { tenantId: 0, warehouseId: payload.warehouseId },
})
expect(http.patch).toHaveBeenCalledWith('/platform/v1/locations/19001/status', { status: 'DISABLED', version: 3 }, {
params: { tenantId: 10001, warehouseId: payload.warehouseId },
params: { tenantId: 0, warehouseId: payload.warehouseId },
})
expect(http.delete).toHaveBeenCalledWith('/platform/v1/locations/19001', {
params: { tenantId: 10001, warehouseId: payload.warehouseId, version: 4 },
params: { tenantId: 0, warehouseId: payload.warehouseId, version: 4 },
})
})
})
@@ -41,7 +41,6 @@ export interface PlatformLocationPage {
export interface PlatformLocationQuery {
page?: number
size?: number
tenantId?: number | string
warehouseId?: number | string
zoneCode?: string
locationCode?: string
@@ -63,6 +62,7 @@ export interface SavePlatformLocationRequest {
}
const basePath = '/platform/v1/locations'
const platformResourceScope = 0
export async function listPlatformLocations(query: PlatformLocationQuery) {
const zoneCode = query.zoneCode?.trim()
@@ -71,7 +71,6 @@ export async function listPlatformLocations(query: PlatformLocationQuery) {
params: {
page: query.page ?? 1,
size: query.size ?? 20,
...(query.tenantId ? { tenantId: query.tenantId } : {}),
...(query.warehouseId ? { warehouseId: query.warehouseId } : {}),
...(zoneCode ? { zoneCode } : {}),
...(locationCode ? { locationCode } : {}),
@@ -90,38 +89,35 @@ export async function listPlatformLocations(query: PlatformLocationQuery) {
}
export async function getPlatformLocation(
tenantId: number | string,
warehouseId: number | string,
id: number | string,
) {
const response = await http.get<ApiEnvelope<PlatformLocationDetail>, ApiEnvelope<PlatformLocationDetail>>(
`${basePath}/${id}`,
{ params: { tenantId, warehouseId } },
{ params: { tenantId: platformResourceScope, warehouseId } },
)
return unwrapApiResponse(response)
}
export async function createPlatformLocation(tenantId: number | string, payload: SavePlatformLocationRequest) {
export async function createPlatformLocation(payload: SavePlatformLocationRequest) {
const response = await http.post<ApiEnvelope<number | string>, ApiEnvelope<number | string>>(basePath, payload, {
params: { tenantId },
params: { tenantId: platformResourceScope },
})
return unwrapApiResponse(response)
}
export async function updatePlatformLocation(
tenantId: number | string,
warehouseId: number | string,
id: number | string,
payload: SavePlatformLocationRequest,
) {
const response = await http.put<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${id}`, payload, {
params: { tenantId, warehouseId },
params: { tenantId: platformResourceScope, warehouseId },
})
return unwrapApiResponse(response)
}
export async function changePlatformLocationStatus(
tenantId: number | string,
warehouseId: number | string,
id: number | string,
status: EditablePlatformLocationStatus,
@@ -130,19 +126,18 @@ export async function changePlatformLocationStatus(
const response = await http.patch<ApiEnvelope<null>, ApiEnvelope<null>>(
`${basePath}/${id}/status`,
{ status, version },
{ params: { tenantId, warehouseId } },
{ params: { tenantId: platformResourceScope, warehouseId } },
)
return unwrapApiResponse(response)
}
export async function deletePlatformLocation(
tenantId: number | string,
warehouseId: number | string,
id: number | string,
version: number,
) {
const response = await http.delete<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${id}`, {
params: { tenantId, warehouseId, version },
params: { tenantId: platformResourceScope, warehouseId, version },
})
return unwrapApiResponse(response)
}