路由表化:迁移订单及订单修改/归属/作废/售后审批路由
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
900fc2f527
commit
babb914c59
5 files changed
+219
-116
No files matched your search
-115
@@ -277,20 +277,6 @@ function createApp(options = {}) {
|
||||
return send(res, 200, actorLedger.materialPurchaseChange(materialChangeMatch[1], actor));
|
||||
}
|
||||
const materialChangeRequest = route.match(/^\/api\/material-purchases\/([a-f0-9-]{36})\/change$/);
|
||||
if (route === '/api/after-sales/changes' && !isPost)
|
||||
return send(res, 200, actorLedger.afterSaleChanges(Object.fromEntries(url.searchParams), actor));
|
||||
const afterSaleChangeMatch = route.match(
|
||||
/^\/api\/after-sales\/changes\/([a-f0-9-]{36})(?:\/(approve|reject))?$/,
|
||||
);
|
||||
if (afterSaleChangeMatch && !isPost) {
|
||||
if (afterSaleChangeMatch[2]) fail('地址不存在', 404);
|
||||
return send(res, 200, actorLedger.afterSaleChange(afterSaleChangeMatch[1], actor));
|
||||
}
|
||||
const afterSaleMatch = route.match(/^\/api\/after-sales\/([a-f0-9-]{36})(?:\/(update))?$/);
|
||||
if (afterSaleMatch && !isPost) {
|
||||
if (afterSaleMatch[2]) fail('地址不存在', 404);
|
||||
return send(res, 200, actorLedger.afterSale(afterSaleMatch[1], actor));
|
||||
}
|
||||
if (route === '/api/customer-materials' && !isPost)
|
||||
return send(res, 200, actorLedger.customerMaterials(Object.fromEntries(url.searchParams), actor));
|
||||
if (route === '/api/recoveries' && !isPost) {
|
||||
@@ -351,28 +337,6 @@ function createApp(options = {}) {
|
||||
if (lockChangeMatch[2]) fail('地址不存在', 404);
|
||||
return send(res, 200, actorLedger.priceLockChange(lockChangeMatch[1], actor));
|
||||
}
|
||||
if (route === '/api/order-note-tags' && !isPost) return send(res, 200, OrderNoteTags.list(actorLedger, actor));
|
||||
if (route === '/api/order-changes' && !isPost)
|
||||
return send(res, 200, actorLedger.orderChanges(Object.fromEntries(url.searchParams), actor));
|
||||
if (route === '/api/order-ownership-changes' && !isPost)
|
||||
return send(res, 200, actorLedger.orderOwnershipChanges(Object.fromEntries(url.searchParams), actor));
|
||||
const ownershipMatch = route.match(/^\/api\/order-ownership-changes\/([a-f0-9-]{36})(?:\/(approve|reject))?$/);
|
||||
if (ownershipMatch && !isPost) {
|
||||
if (ownershipMatch[2]) fail('地址不存在', 404);
|
||||
return send(res, 200, actorLedger.orderOwnershipChange(ownershipMatch[1], actor));
|
||||
}
|
||||
const changeMatch = route.match(/^\/api\/order-changes\/([a-f0-9-]{36})(?:\/(approve|reject))?$/);
|
||||
if (changeMatch && !isPost) {
|
||||
if (changeMatch[2]) fail('地址不存在', 404);
|
||||
return send(res, 200, actorLedger.orderChangeRequest(changeMatch[1], actor));
|
||||
}
|
||||
if (route === '/api/order-cancellations' && !isPost)
|
||||
return send(res, 200, actorLedger.orderCancellations(Object.fromEntries(url.searchParams), actor));
|
||||
const cancellationMatch = route.match(/^\/api\/order-cancellations\/([a-f0-9-]{36})(?:\/(approve|reject))?$/);
|
||||
if (cancellationMatch && !isPost) {
|
||||
if (cancellationMatch[2]) fail('地址不存在', 404);
|
||||
return send(res, 200, actorLedger.orderCancellationRequest(cancellationMatch[1], actor));
|
||||
}
|
||||
const lockMatch = route.match(
|
||||
/^\/api\/price-locks\/([a-f0-9-]+)(?:\/(deliver|edit-context|edit|cancel|change-requests))?$/,
|
||||
);
|
||||
@@ -418,41 +382,8 @@ function createApp(options = {}) {
|
||||
}
|
||||
if (route === '/api/inventory/snapshots' && !isPost)
|
||||
return send(res, 200, actorLedger.inventorySnapshots(Object.fromEntries(url.searchParams)));
|
||||
if (route === '/api/order-book' && !isPost) {
|
||||
const book = actorLedger.orderBook(Object.fromEntries(url.searchParams));
|
||||
if (actor.role !== 'owner') book.peopleCount = null;
|
||||
return send(res, 200, book);
|
||||
}
|
||||
if (route === '/api/order-templates' && !isPost)
|
||||
return send(res, 200, actorLedger.orderTemplates(Object.fromEntries(url.searchParams)));
|
||||
const templateMatch = route.match(/^\/api\/order-templates\/([a-f0-9-]{36})(?:\/(update|delete))?$/);
|
||||
if (templateMatch && !isPost) {
|
||||
if (templateMatch[2]) fail('地址不存在', 404);
|
||||
return send(res, 200, actorLedger.orderTemplate(templateMatch[1]));
|
||||
}
|
||||
if (route === '/api/returned-stock-lots' && !isPost)
|
||||
return send(res, 200, actorLedger.returnedStockLots(Object.fromEntries(url.searchParams), actor));
|
||||
if (route === '/api/paper-number' && !isPost)
|
||||
return send(res, 200, { number: actorLedger.paperNumber(url.searchParams.get('date') || today()) });
|
||||
const orderAfterSaleMatch = route.match(/^\/api\/orders\/([a-f0-9-]+)\/(after-sale|after-sale-preview)$/);
|
||||
if (orderAfterSaleMatch && !isPost) {
|
||||
if (orderAfterSaleMatch[2] !== 'after-sale') fail('地址不存在', 404);
|
||||
return send(res, 200, actorLedger.orderAfterSale(orderAfterSaleMatch[1], actor));
|
||||
}
|
||||
const match = route.match(/^\/api\/orders\/([a-f0-9-]+)(?:\/([a-z]+))?$/);
|
||||
if (match && !isPost) {
|
||||
if (match[2] === 'public') return send(res, 200, actorLedger.publicOrder(match[1]));
|
||||
if (match[2] === 'edit') return send(res, 200, actorLedger.orderEdit(match[1], actor));
|
||||
if (match[2] === 'change') return send(res, 200, actorLedger.orderChange(match[1], actor));
|
||||
if (match[2] === 'ownership') return send(res, 200, actorLedger.orderOwnership(match[1], actor));
|
||||
if (match[2] === 'cancellation') return send(res, 200, actorLedger.orderCancellation(match[1], actor));
|
||||
if (!match[2])
|
||||
return send(res, 200, {
|
||||
...actorLedger.detail(match[1]),
|
||||
printStatus: PrintStatus.projection(actorLedger, 'order', match[1]),
|
||||
});
|
||||
fail('地址不存在', 404);
|
||||
}
|
||||
if (route === '/api/report' && !isPost) {
|
||||
const report = actorLedger.reportFor(Object.fromEntries(url.searchParams), actor);
|
||||
if (actor.role !== 'owner') report.peopleCount = null;
|
||||
@@ -511,12 +442,6 @@ function createApp(options = {}) {
|
||||
// 读取请求体期间账号可能已被停用或重置密码,写入前再次核验会话。
|
||||
const checkedActor = user(req);
|
||||
if (!checkedActor || checkedActor.id !== actor.id) fail('登录已失效,请重新登录', 401);
|
||||
if (orderAfterSaleMatch?.[2] === 'after-sale-preview')
|
||||
return send(
|
||||
res,
|
||||
200,
|
||||
OrderChanges.previewAfterSale(actorLedger, orderAfterSaleMatch[1], b, actor, actorLedger.businessEnv()),
|
||||
);
|
||||
if (route === '/api/material-pools/quote') return send(res, 200, actorLedger.materialPoolQuote(b, actor));
|
||||
if (route === '/api/recoveries/quote') return send(res, 200, actorLedger.recoveryQuote(b, actor));
|
||||
if (recoveryMatch?.[2] === 'quote')
|
||||
@@ -534,15 +459,6 @@ function createApp(options = {}) {
|
||||
return actorLedger.approveRecoveryChange(recoveryChangeMatch[1], b, actor);
|
||||
if (recoveryChangeMatch?.[2] === 'reject')
|
||||
return actorLedger.rejectRecoveryChange(recoveryChangeMatch[1], b, actor);
|
||||
if (route === '/api/order-templates') return actorLedger.saveOrderTemplate(null, b, actor);
|
||||
if (templateMatch && templateMatch[2] === 'update')
|
||||
return actorLedger.saveOrderTemplate(templateMatch[1], b, actor);
|
||||
if (templateMatch && templateMatch[2] === 'delete')
|
||||
return actorLedger.deleteOrderTemplate(templateMatch[1], b, actor);
|
||||
if (route === '/api/orders/issue')
|
||||
return actorLedger.issueOrder(OrderNoteTags.submission(actorLedger, b, actor, b.id), actor);
|
||||
if (route === '/api/orders')
|
||||
return actorLedger.saveOrder(OrderNoteTags.submission(actorLedger, b, actor, b.id), actor);
|
||||
if (route === '/api/material-purchases') return actorLedger.createMaterialPurchase(b, actor);
|
||||
if (route === '/api/material-pools/rolling-enable') return actorLedger.enableRollingMaterial(b, actor);
|
||||
if (materialChangeRequest)
|
||||
@@ -567,37 +483,6 @@ function createApp(options = {}) {
|
||||
return actorLedger.approvePriceLockChange(lockChangeMatch[1], b, actor);
|
||||
if (lockChangeMatch && lockChangeMatch[2] === 'reject')
|
||||
return actorLedger.rejectPriceLockChange(lockChangeMatch[1], b, actor);
|
||||
if (route === '/api/after-sales') return actorLedger.saveAfterSale(b, actor);
|
||||
if (afterSaleMatch && afterSaleMatch[2] === 'update')
|
||||
return actorLedger.updateAfterSale(afterSaleMatch[1], b, actor);
|
||||
if (afterSaleChangeMatch && afterSaleChangeMatch[2] === 'approve')
|
||||
return actorLedger.approveAfterSaleChange(afterSaleChangeMatch[1], b, actor);
|
||||
if (afterSaleChangeMatch && afterSaleChangeMatch[2] === 'reject')
|
||||
return actorLedger.rejectAfterSaleChange(afterSaleChangeMatch[1], b, actor);
|
||||
if (changeMatch && changeMatch[2] === 'approve')
|
||||
return actorLedger.approveOrderChange(changeMatch[1], b, actor);
|
||||
if (changeMatch && changeMatch[2] === 'reject')
|
||||
return actorLedger.rejectOrderChange(changeMatch[1], b, actor);
|
||||
if (ownershipMatch && ownershipMatch[2] === 'approve')
|
||||
return actorLedger.approveOrderOwnership(ownershipMatch[1], b, actor);
|
||||
if (ownershipMatch && ownershipMatch[2] === 'reject')
|
||||
return actorLedger.rejectOrderOwnership(ownershipMatch[1], b, actor);
|
||||
if (match && match[2] === 'ownership') return actorLedger.changeOrderOwnership(match[1], b, actor);
|
||||
if (match && match[2] === 'change')
|
||||
return actorLedger.requestOrderChange(
|
||||
match[1],
|
||||
(b.action ?? 'edit') === 'edit' ? OrderNoteTags.submission(actorLedger, b, actor, match[1]) : b,
|
||||
actor,
|
||||
);
|
||||
if (cancellationMatch && cancellationMatch[2] === 'approve')
|
||||
return actorLedger.approveOrderCancellation(cancellationMatch[1], b, actor);
|
||||
if (cancellationMatch && cancellationMatch[2] === 'reject')
|
||||
return actorLedger.rejectOrderCancellation(cancellationMatch[1], b, actor);
|
||||
if (match && match[2] === 'cancellation') return actorLedger.requestOrderCancellation(match[1], b, actor);
|
||||
if (match && match[2] === 'canceltoday') return actorLedger.cancelOrderToday(match[1], b, actor);
|
||||
if (match && match[2] === 'edit')
|
||||
return actorLedger.editOrder(match[1], OrderNoteTags.submission(actorLedger, b, actor, match[1]), actor);
|
||||
if (match && match[2]) return actorLedger.action(match[1], match[2], b, actor);
|
||||
if (route === '/api/stock') return actorLedger.stock(b, actor);
|
||||
if (inventoryMovementMatch && inventoryMovementMatch[2] === 'update')
|
||||
return actorLedger.updateInventoryMovement(inventoryMovementMatch[1], b, actor);
|
||||
|
||||
Reference in new issue
Block a user