Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,49 +57,65 @@ export class EmailService {

private registerHandlebarsHelpers(): void {
// Equality helper
Handlebars.registerHelper('eq', function (a, b) {
Handlebars.registerHelper('eq', function(a, b) {
return a === b;
});

// Not equal helper
Handlebars.registerHelper('ne', function (a, b) {
Handlebars.registerHelper('ne', function(a, b) {
return a !== b;
});

// Greater than helper
Handlebars.registerHelper('gt', function (a, b) {
Handlebars.registerHelper('gt', function(a, b) {
return a > b;
});

// Less than helper
Handlebars.registerHelper('lt', function (a, b) {
Handlebars.registerHelper('lt', function(a, b) {
return a < b;
});

// Greater than or equal helper
Handlebars.registerHelper('gte', function (a, b) {
Handlebars.registerHelper('gte', function(a, b) {
return a >= b;
});

// Less than or equal helper
Handlebars.registerHelper('lte', function (a, b) {
Handlebars.registerHelper('lte', function(a, b) {
return a <= b;
});

// Logical AND helper
Handlebars.registerHelper('and', function (...args) {
Handlebars.registerHelper('and', function(...args) {
// Remove the last argument which is the options object
const values = args.slice(0, -1);
return values.every((val) => !!val);
});

// Logical OR helper
Handlebars.registerHelper('or', function (...args) {
Handlebars.registerHelper('or', function(...args) {
// Remove the last argument which is the options object
const values = args.slice(0, -1);
return values.some((val) => !!val);
});

Handlebars.registerHelper('today', function(...args) {
const currentDate = new Date();
return currentDate.toDateString();
});

Handlebars.registerHelper('titleCase', function(...args) {
const values = args.slice(0, -1);
const titled = values
.filter(v => typeof v === 'string')
.map(str => str.toLowerCase()
.replace(/\b\w/g, (char: string) => char.toUpperCase()))
.join(" ");

return Handlebars.escapeExpression(titled);
});

this.logger.log('Handlebars helpers registered');
}

Expand Down
2 changes: 1 addition & 1 deletion src/email/templates/birth-certificate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,4 @@
</div>
</div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion src/email/templates/death-certificate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,4 @@
</div>
</div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion src/email/templates/marriage-certificate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,4 @@
</div>
</div>
</body>
</html>
</html>