Skip to content
Open
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
8 changes: 7 additions & 1 deletion apps/backend/src/config/dependencyConfigESS.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import 'reflect-metadata';

import { DataAccessUsersAuthorization } from '../auth/DataAccessUsersAuthorization';
Expand Down Expand Up @@ -65,6 +64,7 @@ import { configureESSDevelopmentEnvironment } from './ess/configureESSEnvironmen
import { configureGraylogLogger } from './ess/configureGrayLogLogger';
import { Tokens } from './Tokens';
import { mapClass, mapValue } from './utils';
import { SMTPMailService } from '../eventHandlers/MailService/SMTP/SMTPMailService';

mapClass(Tokens.RoleDataSource, PostgresRoleDataSource);
mapClass(Tokens.AdminDataSource, PostgresAdminDataSourceWithAutoUpgrade);
Expand Down Expand Up @@ -130,6 +130,12 @@ mapClass(Tokens.AssetRegistrar, EAMAssetRegistrar);

mapClass(Tokens.MailService, SparkPostMailService);

if (isDevelopment) {
mapValue(Tokens.MailService, new SMTPMailService());
} else {
mapClass(Tokens.MailService, SparkPostMailService);
}

mapValue(Tokens.FapDataColumns, FapDataColumns);
mapValue(Tokens.FapDataRow, getDataRow);
mapValue(Tokens.PopulateRow, populateRow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ export class SMTPMailService extends MailService {
);
}

private async resolveEmailTemplate(identifier: string) {
const isNumericIdentifier = /^\d+$/.test(identifier);

if (isNumericIdentifier) {
const byId =
await this.emailTemplateDataSource.getEmailTemplate(+identifier);

if (byId) {
return byId;
}
}

return this.emailTemplateDataSource.getEmailTemplateByName(identifier);
}

private async compileEmailTemplate(options: SendMailOptions): Promise<{
subject: string;
body: string;
Expand All @@ -113,8 +128,8 @@ export class SMTPMailService extends MailService {
return { subject: '= ``', body: '' };
}

const emailTemplate = await this.emailTemplateDataSource.getEmailTemplate(
+options.content.template
const emailTemplate = await this.resolveEmailTemplate(
options.content.template
);

if (!emailTemplate) {
Expand Down
Loading