路由表化:迁移资金/人数/报销与打印路由
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e082069f55
commit
900fc2f527
5 files changed
+279
-205
No files matched your search
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
// 打印状态与打印页(HTML)。
|
||||
const PrintStatus = require('../../print-status');
|
||||
const ShopSettings = require('../../shop-settings');
|
||||
const { receipt } = require('../../printing');
|
||||
const { recoveryCustomerPrintDocument, exchangeCustomerPrintDocument } = require('../../recovery-printing');
|
||||
const { HTML } = require('../http');
|
||||
const { readBody } = require('../middleware/body');
|
||||
|
||||
const STATUS = '/api/print-status/:kind(order|recovery)/:id(uuid)';
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
method: 'GET',
|
||||
path: STATUS,
|
||||
handler: ({ ledger, params: { kind, id }, actor }) => {
|
||||
PrintStatus.access(ledger, kind, id, actor);
|
||||
return PrintStatus.read(ledger, kind, id, actor);
|
||||
},
|
||||
},
|
||||
{
|
||||
// 读请求体前后各核对一次访问权限;不复核会话;事务不同步团队资金。
|
||||
method: 'POST',
|
||||
path: STATUS,
|
||||
direct: true,
|
||||
handler: async ({ req, url, ledger, params: { kind, id }, actor }) => {
|
||||
PrintStatus.access(ledger, kind, id, actor);
|
||||
const body = await readBody(req);
|
||||
PrintStatus.access(ledger, kind, id, actor);
|
||||
return ledger.transact(
|
||||
req.headers['idempotency-key'],
|
||||
actor,
|
||||
{ route: url.pathname, body },
|
||||
() => PrintStatus.update(ledger, kind, id, body, actor),
|
||||
{ syncTeamFunds: false },
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
// 须在 /print/*id 之前。
|
||||
method: 'GET',
|
||||
path: '/print/recoveries/:id(uuid)',
|
||||
contentType: HTML,
|
||||
handler: ({ ledger, params: { id }, actor }) => {
|
||||
const dto = ledger.publicRecovery(id, actor),
|
||||
print = dto.mode === 'exchange' ? exchangeCustomerPrintDocument : recoveryCustomerPrintDocument;
|
||||
return PrintStatus.decorate(print(dto, ShopSettings.printingSettings(ledger)), ledger, 'recovery', id, actor);
|
||||
},
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
path: '/print/*id',
|
||||
contentType: HTML,
|
||||
handler: ({ ledger, url, params: { id }, actor }) => {
|
||||
const order = ledger.detail(id);
|
||||
if (order.recovery_id) {
|
||||
const dto = ledger.publicRecovery(order.recovery_id, actor);
|
||||
return PrintStatus.decorate(
|
||||
exchangeCustomerPrintDocument(dto, ShopSettings.printingSettings(ledger)),
|
||||
ledger,
|
||||
'order',
|
||||
id,
|
||||
actor,
|
||||
);
|
||||
}
|
||||
return PrintStatus.decorate(
|
||||
receipt(ledger.publicOrder(id), ShopSettings.printingSettings(ledger), url.searchParams.get('mode')),
|
||||
ledger,
|
||||
'order',
|
||||
id,
|
||||
actor,
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in new issue
Block a user