feat(procurement): show customer sample fulfillment and charges
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { ProcurementCreate } from './api/procurement'
|
||||
import { buildProcurementCreate, emptyProcurementDraft } from './procurementPresentation'
|
||||
|
||||
/** Restore the exact request; an unknown result cannot become a new order. */
|
||||
export function restoreProcurementSubmission(raw: string): ProcurementCreate {
|
||||
const saved: unknown = JSON.parse(raw)
|
||||
if (!saved || typeof saved !== 'object' || Array.isArray(saved)) throw new Error('提交记录格式错误')
|
||||
const value = saved as Record<string, unknown>
|
||||
for (const key of ['customerName', 'purchaseCategory', 'productName', 'currency', 'receivingAddress', 'contactName', 'contactPhone', 'idempotencyKey']) if (typeof value[key] !== 'string') throw new Error('提交记录不完整')
|
||||
if (typeof value.purchaseQuantity !== 'number' || typeof value.budgetUnitPrice !== 'number' || !String(value.idempotencyKey).trim() || String(value.idempotencyKey).length > 255) throw new Error('提交记录不完整')
|
||||
for (const key of ['productSpecification', 'productUrl', 'remark']) if (value[key] !== undefined && typeof value[key] !== 'string') throw new Error('提交记录不完整')
|
||||
if (value.currency !== 'CNY' && value.currency !== 'USD') throw new Error('提交记录币种无效')
|
||||
return buildProcurementCreate({ ...emptyProcurementDraft(), purchaseCategory: String(value.purchaseCategory), productName: String(value.productName),
|
||||
productSpecification: String(value.productSpecification || ''), productUrl: String(value.productUrl || ''), purchaseQuantity: String(value.purchaseQuantity),
|
||||
budgetUnitPrice: String(value.budgetUnitPrice), currency: value.currency, receivingAddress: String(value.receivingAddress), contactName: String(value.contactName),
|
||||
contactPhone: String(value.contactPhone), remark: String(value.remark || '') }, String(value.customerName), String(value.idempotencyKey))
|
||||
}
|
||||
export function definitelyRejected(error: { code?: string; status?: number }) {
|
||||
return ['A0400', 'A0401', 'A0403', 'A0422'].includes(error.code || '') || [400, 401, 403, 422].includes(error.status || 0)
|
||||
}
|
||||
export function procurementRequestKey(provider: Pick<Crypto, 'getRandomValues'> & Partial<Pick<Crypto, 'randomUUID'>> = globalThis.crypto) {
|
||||
if (provider.randomUUID) return provider.randomUUID()
|
||||
return `proc-${Array.from(provider.getRandomValues(new Uint32Array(4)), value => value.toString(16).padStart(8, '0')).join('')}`
|
||||
}
|
||||
Reference in New Issue
Block a user