优化
This commit is contained in:
@@ -5,6 +5,12 @@ const OCEAN = '/api/platform/v1/ocean-bookings'
|
||||
const PORT = '/api/platform/v1/port-schedules'
|
||||
|
||||
function id(value) { return value == null ? '' : String(value) }
|
||||
export function matchesManualScheduleScope(resource, expected) {
|
||||
return Boolean(resource?.id)
|
||||
&& id(resource.customerId) === id(expected.customerId)
|
||||
&& id(resource.oceanBookingId) === id(expected.oceanBookingId)
|
||||
&& id(resource.containerBookingId) === id(expected.containerBookingId)
|
||||
}
|
||||
function codeOf(response) { return response?.body?.code == null ? 'missing' : String(response.body.code) }
|
||||
function data(response) { return codeOf(response) === '200' ? response.body.data : null }
|
||||
function localIso(value) { return value.toISOString().slice(0, 19) }
|
||||
@@ -60,7 +66,8 @@ async function ensureOcean(context, suffix) {
|
||||
|
||||
async function createManualSchedule(context, suffix, oceanBookingId) {
|
||||
const existing = context.createdResources?.portSchedule
|
||||
if (existing?.id && id(existing.oceanBookingId) === oceanBookingId) return id(existing.id)
|
||||
const expectedScope = { customerId: '10001', oceanBookingId, containerBookingId: null }
|
||||
if (matchesManualScheduleScope(existing, expectedScope)) return id(existing.id)
|
||||
const body = {
|
||||
expectedVersion: 0,
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user