From 86b2e4679831b46c8d2f53547d7b2a66f9c40e1d Mon Sep 17 00:00:00 2001 From: Eric Gullickson <16152721+ericgullickson@users.noreply.github.com> Date: Sat, 31 Jan 2026 20:02:51 -0600 Subject: [PATCH] fix: replace template conditionals with simple variable substitution (refs #59) The TemplateService only supports {{variable}} substitution, not Handlebars-style conditionals. Changed to use a single {{additionalInfo}} variable that is built in the service code based on upgrade/downgrade status. Co-Authored-By: Claude Opus 4.5 --- .../domain/notifications.service.ts | 17 +++++++++++------ .../007_subscription_tier_change_template.sql | 10 ++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/backend/src/features/notifications/domain/notifications.service.ts b/backend/src/features/notifications/domain/notifications.service.ts index de21b6a..7c1684c 100644 --- a/backend/src/features/notifications/domain/notifications.service.ts +++ b/backend/src/features/notifications/domain/notifications.service.ts @@ -270,15 +270,22 @@ export class NotificationsService { enterprise: 'unlimited', }; + // Build additional info based on change type + let additionalInfo = ''; + if (isDowngrade) { + const vehicleLimit = vehicleLimitMap[newTier.toLowerCase()] || '2'; + additionalInfo = `As a result of this change, you now have access to ${vehicleLimit} vehicles. Any vehicles beyond this limit will be hidden but your data remains safe.`; + } else if (isUpgrade) { + additionalInfo = `You now have access to all the features included in the ${this.formatTierName(newTier)} tier. Enjoy your enhanced MotoVaultPro experience!`; + } + const variables = { userName, changeType, previousTier: this.formatTierName(previousTier), newTier: this.formatTierName(newTier), reason: reasonDisplayMap[reason] || reason, - isDowngrade: isDowngrade ? 'true' : '', - isUpgrade: isUpgrade ? 'true' : '', - vehicleLimit: vehicleLimitMap[newTier.toLowerCase()] || '2', + additionalInfo, }; const subject = this.templateService.render(template.subject, variables); @@ -436,9 +443,7 @@ export class NotificationsService { previousTier: 'Free', newTier: 'Pro', reason: 'Subscription upgrade', - isDowngrade: '', - isUpgrade: 'true', - vehicleLimit: '5', + additionalInfo: 'You now have access to all the features included in the Pro tier. Enjoy your enhanced MotoVaultPro experience!', }; default: return baseVariables; diff --git a/backend/src/features/notifications/migrations/007_subscription_tier_change_template.sql b/backend/src/features/notifications/migrations/007_subscription_tier_change_template.sql index 536e55f..1cd656c 100644 --- a/backend/src/features/notifications/migrations/007_subscription_tier_change_template.sql +++ b/backend/src/features/notifications/migrations/007_subscription_tier_change_template.sql @@ -32,19 +32,13 @@ Previous Tier: {{previousTier}} New Tier: {{newTier}} Reason: {{reason}} -{{#if isDowngrade}} -As a result of this change, you now have access to {{vehicleLimit}} vehicles. Any vehicles beyond this limit will be hidden but your data remains safe. -{{/if}} - -{{#if isUpgrade}} -You now have access to all the features included in the {{newTier}} tier. Enjoy your enhanced MotoVaultPro experience! -{{/if}} +{{additionalInfo}} If you have any questions, please contact support. Best regards, MotoVaultPro Team', - '["userName", "changeType", "previousTier", "newTier", "reason", "isDowngrade", "isUpgrade", "vehicleLimit"]', + '["userName", "changeType", "previousTier", "newTier", "reason", "additionalInfo"]', '