enhance: email template functions to include tenant and organization in header and footer#852
Conversation
…codes in header and footer retrieval
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/database/queries/notificationTemplate.js (1)
58-58: Add default value fortenantCodeparameter.The function signature has
tenantCodewithout a default value, butsrc/services/organization.jsline 111 calls this function with only one parameter. This causestenantCodeto beundefined, which is then used in the filter at line 67.Apply this diff to fix the backwards compatibility issue:
-exports.findOneEmailTemplate = async (code, orgCode = null, tenantCode) => { +exports.findOneEmailTemplate = async (code, orgCode = null, tenantCode = null) => {Additionally, you may need to conditionally add
tenant_codeto the filter only when it's provided:const filter = { code: code, type: 'email', - tenant_code: tenantCode, status: common.ACTIVE_STATUS, organization_code: orgCode && orgCode != defaultOrgCode ? { [Op.or]: [orgCode, defaultOrgCode], } : defaultOrgCode, } + + if (tenantCode) { + filter.tenant_code = tenantCode + }
♻️ Duplicate comments (1)
src/database/queries/notificationTemplate.js (1)
97-101: Same fallback concern applies to footer retrieval.The footer lookup has the same limitation as the header: no fallback to
DEFAULT_ORGANISATION_CODE. This could result in missing footers when the main template uses the default organization fallback.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/database/queries/notificationTemplate.js(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/database/queries/**
⚙️ CodeRabbit configuration file
Review database queries for performance. Check for N+1 problems and ensure indexes can be used.
Files:
src/database/queries/notificationTemplate.js
🧬 Code graph analysis (1)
src/database/queries/notificationTemplate.js (2)
src/services/organization.js (2)
templateData(112-112)tenantCode(281-281)src/utils/notification.js (2)
templateData(14-18)templateData(58-62)
Summary by CodeRabbit