test(回归): 按新裁决更新 SEC-4 边界用例与散客入口契约;路由裸 SQL 移入 service
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

This commit is contained in:
Ubuntu
2026-10-19 17:44:46 +08:00
parent 35213fd2a0
commit 8a08686e1a
5 changed files with 65 additions and 30 deletions
@@ -126,27 +126,19 @@ router.put('/quote/sheets/:code', authMiddleware, async (req: AuthRequest, res:
/** 本单当前挂的客户(编辑时必须原样回传,保证"本单客户不变") */
let ownCustomerCodes: string[] | undefined;
if (rawCustomerCodes && rawCustomerCodes.length) {
const { pool } = await import('../../../db');
const current = await pool.query<{ customer_code: string }>(
`SELECT customer_code FROM customer_quote_sheet_customers WHERE quote_sheet_code = $1`,
[req.params.code]
);
const currentCodes = new Set(current.rows.map((r) => String(r.customer_code)));
ownCustomerCodes = Array.from(currentCodes);
const extra = rawCustomerCodes.filter((c) => !currentCodes.has(c));
if (extra.length) {
const taken = await pool.query<{ customer_code: string }>(
`SELECT DISTINCT customer_code FROM customer_quote_sheet_customers WHERE customer_code = ANY($1::text[])`,
[extra]
);
if ((taken.rowCount || 0) > 0) {
return res.status(400).json({
error: 'customer_already_quoted',
error_description: `以下客户名下已有报价单,不能追加:${taken.rows.map((r) => r.customer_code).join('、')}`,
});
}
customersToCreate = extra;
const { resolveEditCustomerSplit } = await import('../../../services/quoteSheetService');
const split = await resolveEditCustomerSplit({
quoteSheetCode: String(req.params.code || ''),
requestedCustomerCodes: rawCustomerCodes,
});
ownCustomerCodes = split.ownCustomerCodes;
if (split.takenCustomerCodes.length) {
return res.status(400).json({
error: 'customer_already_quoted',
error_description: `以下客户名下已有报价单,不能追加:${split.takenCustomerCodes.join('、')}`,
});
}
customersToCreate = split.customersToCreate;
}
/**
* ⚠️ 只有"本单自己的客户"能传给编辑服务: