From bdee85782855c54ca976ea49f97960047d8cee23 Mon Sep 17 00:00:00 2001 From: seaznCode Date: Wed, 14 Jan 2026 22:16:15 +0100 Subject: [PATCH] feat: enhance deactivation logic for conflicting active contract templates to handle null contract types and user types --- repositories/template/DocumentTemplateRepository.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/repositories/template/DocumentTemplateRepository.js b/repositories/template/DocumentTemplateRepository.js index 7980df7..5dd113e 100644 --- a/repositories/template/DocumentTemplateRepository.js +++ b/repositories/template/DocumentTemplateRepository.js @@ -166,12 +166,18 @@ class DocumentTemplateRepository { SET state = 'inactive', updatedAt = NOW() WHERE id <> ? AND type = 'contract' - AND contract_type = ? + AND ( + contract_type = ? + OR (contract_type IS NULL AND ? = 'contract') + ) AND lang = ? 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 { if (conn) { const [res] = await conn.execute(query, params);