test(回归): 按新裁决更新 SEC-4 边界用例与散客入口契约;路由裸 SQL 移入 service
This commit is contained in:
@@ -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;
|
||||
}
|
||||
/**
|
||||
* ⚠️ 只有"本单自己的客户"能传给编辑服务:
|
||||
|
||||
Reference in New Issue
Block a user