From bca08f8749c4cf307068f8faad67deb2b9bea6e5 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Fri, 2 Oct 2026 23:16:19 +0800 Subject: [PATCH] fix(orders): send version and idempotency key for platform cancellation --- .../api/platformFirstLegOrders.test.ts | 8 +++----- .../api/platformFirstLegOrders.ts | 17 +++++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/modules/first-leg-orders/api/platformFirstLegOrders.test.ts b/src/modules/first-leg-orders/api/platformFirstLegOrders.test.ts index c141fa9c..2253c25c 100644 --- a/src/modules/first-leg-orders/api/platformFirstLegOrders.test.ts +++ b/src/modules/first-leg-orders/api/platformFirstLegOrders.test.ts @@ -5,7 +5,6 @@ import { acceptPlatformFirstLegOrder, approvePlatformFirstLegOrder, cancelPlatformFirstLegOrder, - completePlatformFirstLegOrder, getPlatformFirstLegOrder, listPlatformFirstLegOrders, startPlatformFirstLegOrder, @@ -82,15 +81,14 @@ describe('platform first-leg order API', () => { await approvePlatformFirstLegOrder('10001', '90001') await acceptPlatformFirstLegOrder('10001', '90001') await startPlatformFirstLegOrder('10001', '90001') - await completePlatformFirstLegOrder('10001', '90001') - await cancelPlatformFirstLegOrder('10001', '90001', '客户取消') + await cancelPlatformFirstLegOrder('10001', '90001', { expectedVersion: 7, reason: '客户取消' }, 'cancel-original-key') expect(http.get).toHaveBeenCalledWith('/platform/v1/orders/first-leg/90001', { params: { tenantId: '10001' } }) expect(http.post).toHaveBeenNthCalledWith(1, '/platform/v1/orders/first-leg/90001/approve', undefined, { params: { tenantId: '10001' } }) expect(http.post).toHaveBeenNthCalledWith(2, '/platform/v1/orders/first-leg/90001/accept', undefined, { params: { tenantId: '10001' } }) expect(http.post).toHaveBeenNthCalledWith(3, '/platform/v1/orders/first-leg/90001/start', undefined, { params: { tenantId: '10001' } }) - expect(http.post).toHaveBeenNthCalledWith(4, '/platform/v1/orders/first-leg/90001/complete', undefined, { params: { tenantId: '10001' } }) - expect(http.post).toHaveBeenNthCalledWith(5, '/platform/v1/orders/first-leg/90001/cancel', { reason: '客户取消' }, { params: { tenantId: '10001' } }) + expect(http.post).toHaveBeenNthCalledWith(4, '/platform/v1/orders/first-leg/90001/cancel', { expectedVersion: 7, reason: '客户取消' }, { params: { tenantId: '10001' }, headers: { 'Idempotency-Key': 'cancel-original-key' } }) + expect(http.post).toHaveBeenCalledTimes(4) }) it('writes the backend express contract as names, not a guessed master-data ID', async () => { diff --git a/src/modules/first-leg-orders/api/platformFirstLegOrders.ts b/src/modules/first-leg-orders/api/platformFirstLegOrders.ts index 45a9d704..eedfdac4 100644 --- a/src/modules/first-leg-orders/api/platformFirstLegOrders.ts +++ b/src/modules/first-leg-orders/api/platformFirstLegOrders.ts @@ -184,12 +184,17 @@ export function startPlatformFirstLegOrder(tenantId: string, orderId: string) { return postData(`/platform/v1/orders/first-leg/${orderId}/start`, undefined, { tenantId }) } -export function completePlatformFirstLegOrder(tenantId: string, orderId: string) { - return postData(`/platform/v1/orders/first-leg/${orderId}/complete`, undefined, { tenantId }) -} - -export function cancelPlatformFirstLegOrder(tenantId: string, orderId: string, reason: string) { - return postData(`/platform/v1/orders/first-leg/${orderId}/cancel`, { reason }, { tenantId }) +export async function cancelPlatformFirstLegOrder( + tenantId: string, + orderId: string, + payload: { expectedVersion: number; reason: string }, + idempotencyKey: string, +) { + const response = await http.post, ApiEnvelope>( + `/platform/v1/orders/first-leg/${orderId}/cancel`, payload, + { params: { tenantId }, headers: { 'Idempotency-Key': idempotencyKey } }, + ) + return unwrapApiResponse(response) } export function updatePlatformFirstLegOrderExpress(