适配 M002 V3 字段矩阵前端交互
This commit is contained in:
@@ -14,6 +14,7 @@ import type {
|
||||
ReservationOrderDetailResult,
|
||||
ReservationOrderListFilters,
|
||||
ReservationOrderListResult,
|
||||
ReservationRecord,
|
||||
ReservationTaskAuditListResult,
|
||||
ReservationTaskDetailResult,
|
||||
ReservationTaskListFilters,
|
||||
@@ -201,8 +202,8 @@ function fixtureManualReviewResolution(
|
||||
request: ReservationManualReviewResolutionRequest,
|
||||
): Promise<ReservationManualReviewResolutionResult> {
|
||||
return fixtureTaskDetail(taskId).then((detail) => {
|
||||
const confirmedPayload = Object.fromEntries(
|
||||
request.field_overrides.map((item) => [fieldPointerToFixturePath(item.field_pointer), item.value]),
|
||||
const fieldValues = Object.fromEntries(
|
||||
request.field_overrides.map((item) => [fieldOverrideToFixturePath(item), item.value]),
|
||||
)
|
||||
return {
|
||||
task_id: detail.task_id,
|
||||
@@ -215,19 +216,86 @@ function fixtureManualReviewResolution(
|
||||
field_overrides: request.field_overrides,
|
||||
},
|
||||
confirmed_payload: {
|
||||
...(detail.confirmed_payload ?? {}),
|
||||
...confirmedPayload,
|
||||
field_values: fieldValues,
|
||||
legacy_field_values: legacyFieldValues(fieldValues),
|
||||
effective_payload: effectivePayload(fieldValues),
|
||||
},
|
||||
opera_operations: detail.opera_operations,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function fieldPointerToFixturePath(fieldPointer: string): string {
|
||||
if (fieldPointer === '/extracted_fields/room_items/0/pms_room_type_code') {
|
||||
return 'extracted_fields.pms_room_type_code'
|
||||
function fieldOverrideToFixturePath(
|
||||
fieldOverride: ReservationManualReviewResolutionRequest['field_overrides'][number],
|
||||
): string {
|
||||
if (fieldOverride.field_path) {
|
||||
return canonicalFixtureFieldPath(fieldOverride.field_path)
|
||||
}
|
||||
return fieldPointer.replace(/^\//, '').replace(/\//g, '.')
|
||||
if (fieldOverride.field_pointer) {
|
||||
return canonicalFixtureFieldPath(fieldOverride.field_pointer.replace(/^\//, '').replace(/\//g, '.'))
|
||||
}
|
||||
throw new Error('Manual review field override requires field_pointer or field_path')
|
||||
}
|
||||
|
||||
function canonicalFixtureFieldPath(fieldPath: string): string {
|
||||
if (fieldPath === 'extracted_fields.room_quantity') {
|
||||
return 'extracted_fields.room_items.0.room_quantity'
|
||||
}
|
||||
if (fieldPath === 'extracted_fields.room_type') {
|
||||
return 'extracted_fields.room_items.0.room_type_raw'
|
||||
}
|
||||
if (fieldPath === 'extracted_fields.pms_room_type_code') {
|
||||
return 'extracted_fields.room_items.0.pms_room_type_code'
|
||||
}
|
||||
return fieldPath
|
||||
}
|
||||
|
||||
function legacyFieldValues(fieldValues: Record<string, unknown>): Record<string, unknown> {
|
||||
return Object.entries(fieldValues).reduce<Record<string, unknown>>((legacyValues, [fieldPath, value]) => {
|
||||
if (fieldPath === 'extracted_fields.room_items.0.room_quantity') {
|
||||
legacyValues['extracted_fields.room_quantity'] = value
|
||||
}
|
||||
if (fieldPath === 'extracted_fields.room_items.0.room_type_raw') {
|
||||
legacyValues['extracted_fields.room_type'] = value
|
||||
}
|
||||
if (fieldPath === 'extracted_fields.room_items.0.pms_room_type_code') {
|
||||
legacyValues['extracted_fields.pms_room_type_code'] = value
|
||||
}
|
||||
return legacyValues
|
||||
}, {})
|
||||
}
|
||||
|
||||
function effectivePayload(fieldValues: Record<string, unknown>): ReservationRecord {
|
||||
return Object.entries(fieldValues).reduce<ReservationRecord>((payload, [fieldPath, value]) => {
|
||||
writeNestedFieldValue(payload, fieldPath, value)
|
||||
return payload
|
||||
}, {})
|
||||
}
|
||||
|
||||
function writeNestedFieldValue(payload: ReservationRecord, fieldPath: string, value: unknown): void {
|
||||
const segments = fieldPath.split('.')
|
||||
let current: ReservationRecord | unknown[] = payload
|
||||
segments.forEach((segment, index) => {
|
||||
const last = index === segments.length - 1
|
||||
const nextSegment = segments[index + 1]
|
||||
if (last) {
|
||||
if (Array.isArray(current)) {
|
||||
current[Number(segment)] = value
|
||||
} else {
|
||||
current[segment] = value
|
||||
}
|
||||
return
|
||||
}
|
||||
const nextIsArray = nextSegment !== undefined && /^\d+$/.test(nextSegment)
|
||||
if (Array.isArray(current)) {
|
||||
const arrayIndex = Number(segment)
|
||||
current[arrayIndex] ??= nextIsArray ? [] : {}
|
||||
current = current[arrayIndex] as ReservationRecord | unknown[]
|
||||
return
|
||||
}
|
||||
current[segment] ??= nextIsArray ? [] : {}
|
||||
current = current[segment] as ReservationRecord | unknown[]
|
||||
})
|
||||
}
|
||||
|
||||
async function fixtureOperaOperation(
|
||||
|
||||
Reference in New Issue
Block a user