feat: enhance deactivation logic for conflicting active contract templates to handle null contract types and user types

This commit is contained in:
seaznCode 2026-01-14 22:16:15 +01:00
parent aa98d9ac37
commit bdee857828

View File

@ -166,12 +166,18 @@ class DocumentTemplateRepository {
SET state = 'inactive', updatedAt = NOW() SET state = 'inactive', updatedAt = NOW()
WHERE id <> ? WHERE id <> ?
AND type = 'contract' AND type = 'contract'
AND contract_type = ? AND (
contract_type = ?
OR (contract_type IS NULL AND ? = 'contract')
)
AND lang = ? AND lang = ?
AND state = 'active' AND state = 'active'
AND user_type IN (${overlap.map(() => '?').join(', ')}) AND (
user_type IN (${overlap.map(() => '?').join(', ')})
OR user_type IS NULL
)
`; `;
const params = [excludeId, safeContractType, safeLang, ...overlap]; const params = [excludeId, safeContractType, safeContractType, safeLang, ...overlap];
try { try {
if (conn) { if (conn) {
const [res] = await conn.execute(query, params); const [res] = await conn.execute(query, params);