* feat: restart cmd added in aio service * feat: nestjs config package added * test: fix all broken test case * feat: infra config module add with get-update-reset functionality * test: fix test case failure * feat: update infra configs mutation added * feat: utilise ConfigService in util functions * chore: remove saml stuff * feat: removed saml stuffs * fix: config service precedence * fix: mailer module init with right env value * feat: added mutations and query * feat: add query infra-configs * fix: mailer module init issue * chore: smtp url validation added * fix: all sso disabling is handled * fix: pnpm i without db connection * fix: allowedAuthProviders and enableAndDisableSSO * fix: validateSMTPUrl check * feat: get api added for fetch provider list * feat: feedback resolve * chore: update code comments * fix: uppercase issue of VITE_ALLOWED_AUTH_PROVIDERS * chore: update lockfile * fix: add validation checks for MAILER_ADDRESS_FROM * test: fix test case * chore: feedback resolve * chore: renamed an enum * chore: app shutdown way changed --------- Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { Global, Module } from '@nestjs/common';
|
|
import { MailerModule as NestMailerModule } from '@nestjs-modules/mailer';
|
|
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
|
|
import { MailerService } from './mailer.service';
|
|
import { throwErr } from 'src/utils';
|
|
import {
|
|
MAILER_FROM_ADDRESS_UNDEFINED,
|
|
MAILER_SMTP_URL_UNDEFINED,
|
|
} from 'src/errors';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { loadInfraConfiguration } from 'src/infra-config/helper';
|
|
|
|
@Global()
|
|
@Module({
|
|
imports: [],
|
|
providers: [MailerService],
|
|
exports: [MailerService],
|
|
})
|
|
export class MailerModule {
|
|
static async register() {
|
|
const env = await loadInfraConfiguration();
|
|
|
|
let mailerSmtpUrl = env.INFRA.MAILER_SMTP_URL;
|
|
let mailerAddressFrom = env.INFRA.MAILER_ADDRESS_FROM;
|
|
|
|
if (!env.INFRA.MAILER_SMTP_URL || !env.INFRA.MAILER_ADDRESS_FROM) {
|
|
const config = new ConfigService();
|
|
mailerSmtpUrl = config.get('MAILER_SMTP_URL');
|
|
mailerAddressFrom = config.get('MAILER_ADDRESS_FROM');
|
|
}
|
|
|
|
return {
|
|
module: MailerModule,
|
|
imports: [
|
|
NestMailerModule.forRoot({
|
|
transport: mailerSmtpUrl ?? throwErr(MAILER_SMTP_URL_UNDEFINED),
|
|
defaults: {
|
|
from: mailerAddressFrom ?? throwErr(MAILER_FROM_ADDRESS_UNDEFINED),
|
|
},
|
|
template: {
|
|
dir: __dirname + '/templates',
|
|
adapter: new HandlebarsAdapter(),
|
|
},
|
|
}),
|
|
],
|
|
};
|
|
}
|
|
}
|