优化
This commit is contained in:
@@ -391,12 +391,27 @@ export async function run(context) {
|
||||
{ expectedVersion: 0, data: bookingDraft }, { 'Idempotency-Key': `${context.marker}-loading-booking-create` })
|
||||
const bookingCreatedDraft = context.apiSuccess(MODULE, '登记含渠道仓库和运输快照的 DRAFT 订舱', bookingCreate, '', OPTIONS)
|
||||
const bookingId = id(bookingCreatedDraft?.oceanBooking?.id)
|
||||
if (!bookingId) return
|
||||
const bookingDocumentForm = new FormData()
|
||||
bookingDocumentForm.append('expectedVersion', String(Number(bookingCreatedDraft?.oceanBooking?.version)))
|
||||
bookingDocumentForm.append('documentType', 'BOOKING_CONFIRMATION')
|
||||
bookingDocumentForm.append('file', new Blob([`${context.marker}-BOOKING_CONFIRMATION`], { type: 'text/plain' }),
|
||||
`booking-confirmation-${context.marker}.txt`)
|
||||
const bookingDocumentResponse = await context.requestMultipart('POST',
|
||||
`/api/platform/v1/ocean-bookings/${bookingId}/documents/upload`, bookingDocumentForm, context.token,
|
||||
{ 'Idempotency-Key': `${context.marker}-loading-booking-document`.slice(0, 128) })
|
||||
const bookingDocument = context.apiSuccess(MODULE, '上传有效订舱确认文件', bookingDocumentResponse, '', OPTIONS)
|
||||
const releaseVersion = Number(bookingDocument?.bookingVersion)
|
||||
context.assert(MODULE, '订舱确认文件已关联且版本递增', bookingDocumentResponse,
|
||||
Boolean(bookingDocument?.document?.id) && bookingDocument?.document?.documentType === 'BOOKING_CONFIRMATION'
|
||||
&& Number.isInteger(releaseVersion),
|
||||
`documentId=${id(bookingDocument?.document?.id) || 'missing'}, bookingVersion=${bookingDocument?.bookingVersion ?? 'missing'}`, OPTIONS)
|
||||
if (!Number.isInteger(releaseVersion)) return
|
||||
const bookingRelease = await request(context, 'POST', `/api/platform/v1/ocean-bookings/${bookingId}/release`, {
|
||||
expectedVersion: Number(bookingCreatedDraft?.oceanBooking?.version), reason: context.marker,
|
||||
expectedVersion: releaseVersion, reason: context.marker,
|
||||
}, { 'Idempotency-Key': `${context.marker}-loading-booking-release`.slice(0, 128) })
|
||||
const bookingCreated = context.apiSuccess(MODULE, '放舱订舱并冻结运输事实', bookingRelease, '', OPTIONS)
|
||||
const bookingNo = id(bookingCreated?.oceanBooking?.bookingNo)
|
||||
if (!bookingId) return
|
||||
const confirmedBooking = bookingCreated
|
||||
const transportFields = ['billOfLadingNo', 'vesselName', 'voyageNo', 'estimatedSailingAt', 'estimatedArrivalAt']
|
||||
const frozenTransport = Object.fromEntries(transportFields.map((field) => [field, confirmedBooking?.oceanBooking?.[field]]))
|
||||
|
||||
Reference in New Issue
Block a user