diff --git a/src/common/decorators/validation/validation-field.generator.ts b/src/common/decorators/validation/validation-field.generator.ts index 87cf6643..721630a1 100644 --- a/src/common/decorators/validation/validation-field.generator.ts +++ b/src/common/decorators/validation/validation-field.generator.ts @@ -18,17 +18,17 @@ import type { NumberFieldOptions, StringFieldOptions } from "@common/@types"; import { Sanitize, Trim } from "./transform.decorator"; export class ValidatorFieldBuilder { - private decoratorsToApply: PropertyDecorator[]; + private decoratorsToApply!: PropertyDecorator[]; constructor(readonly options: NumberFieldOptions & StringFieldOptions) {} number() { this.decoratorsToApply.push( Type(() => Number), - Min(this.options.min, { + Min(this.options.min!, { message: validationI18nMessage("validation.min"), }), - Max(this.options.max, { + Max(this.options.max!, { message: validationI18nMessage("validation.max"), }), ); diff --git a/src/common/misc/file.ts b/src/common/misc/file.ts index 5e116f0a..c1ea3ee1 100644 --- a/src/common/misc/file.ts +++ b/src/common/misc/file.ts @@ -15,7 +15,7 @@ export const ImageMulterOption: MulterOptions = { if (!FileType.IMAGE.test(file.mimetype)) return callback(new Error(MULTER_IMAGE_FILTER), false); - return callback(undefined, true); + return callback(null, true); }, }; diff --git a/src/lib/config/config.module.ts b/src/lib/config/config.module.ts index 42473f79..be8b145a 100644 --- a/src/lib/config/config.module.ts +++ b/src/lib/config/config.module.ts @@ -22,6 +22,8 @@ import { redisConfigValidationSchema, sentry, sentryConfigurationValidationSchema, + stripe, + stripeonfigValidationSchema, throttle, throttleConfigValidationSchema, } from "./configs"; @@ -42,6 +44,7 @@ import { facebookOauth, throttle, sentry, + stripe ], cache: true, isGlobal: true, @@ -57,6 +60,7 @@ import { ...facebookOauthConfigValidationSchema, ...throttleConfigValidationSchema, ...sentryConfigurationValidationSchema, + ...stripeonfigValidationSchema }), validationOptions: { abortEarly: true, diff --git a/src/lib/config/configs/mail.config.ts b/src/lib/config/configs/mail.config.ts index b88286a9..5f535c96 100644 --- a/src/lib/config/configs/mail.config.ts +++ b/src/lib/config/configs/mail.config.ts @@ -24,7 +24,7 @@ export const mail = registerAs("mail", () => ({ password: process.env.MAIL_PASSWORD, host: process.env.MAIL_HOST, port: process.env.MAIL_PORT ?? +process.env.MAIL_PORT, - server: process.env.MAIL_SERVER, + type: process.env.MAIL_SERVER, previewEmail: process.env.MAIL_PREVIEW_EMAIL, bccList: process.env?.MAIL_BCC_LIST ? process.env.MAIL_BCC_LIST.split(",") : [], templateDir: process.env.MAIL_TEMPLATE_DIR, diff --git a/src/lib/config/configs/stripe.config.ts b/src/lib/config/configs/stripe.config.ts index 1595a53b..0643d32b 100644 --- a/src/lib/config/configs/stripe.config.ts +++ b/src/lib/config/configs/stripe.config.ts @@ -1,7 +1,7 @@ import { registerAs } from "@nestjs/config"; import Joi from "joi"; -export const strpeonfigValidationSchema = { +export const stripeonfigValidationSchema = { STRIPE_API_KEY: Joi.string().required(), STRIPE_ACCOUNT: Joi.string().required(), STRIPE_CONNECT: Joi.string().required(), @@ -9,6 +9,6 @@ export const strpeonfigValidationSchema = { export const stripe = registerAs("stripe", () => ({ apiKey: process.env.STRIPE_API_KEY, - connect: process.env.STRIPE_ACCOUNT, - account: process.env.STRIPE_CONNECT, + connect: process.env.STRIPE_CONNECT, + account: process.env.STRIPE_ACCOUNT, })); diff --git a/src/lib/mailer/index.ts b/src/lib/mailer/index.ts index 1427d627..75116b9a 100644 --- a/src/lib/mailer/index.ts +++ b/src/lib/mailer/index.ts @@ -1,6 +1,6 @@ import { Global, Module } from "@nestjs/common"; import { ConfigModule, ConfigService } from "@nestjs/config"; -import { TemplateEngine } from "@common/@types"; +import { Server, TemplateEngine } from "@common/@types"; import { MailModule } from "./mailer.module"; @Global() @@ -10,11 +10,13 @@ import { MailModule } from "./mailer.module"; imports: [ConfigModule], inject: [ConfigService], useFactory: (configService: ConfigService) => ({ - host: configService.get("mail.host", { infer: true }), - port: configService.get("mail.port", { infer: true }), - username: configService.get("mail.username", { infer: true }), - password: configService.get("mail.password", { infer: true }), - server: configService.get("mail.server", { infer: true }), + credentials: { + type: configService.get("mail.type", { infer: true }) as Server.SMTP, + host: configService.get("mail.host", { infer: true }), + port: configService.get("mail.port", { infer: true }), + username: configService.get("mail.username", { infer: true }), + password: configService.get("mail.password", { infer: true }), + }, previewEmail: configService.get("mail.previewEmail", { infer: true }), templateDir: configService.get("mail.templateDir", { infer: true }), templateEngine: { diff --git a/src/lib/mailer/mailer.options.ts b/src/lib/mailer/mailer.options.ts index 0f19bab9..e7204cfd 100644 --- a/src/lib/mailer/mailer.options.ts +++ b/src/lib/mailer/mailer.options.ts @@ -3,16 +3,24 @@ import type { Options as PugOptions } from "pug"; import type { Server, TemplateEngine } from "@common/@types"; export interface MailModuleOptions { - host?: string - port?: number - password?: string - username?: string + + credentials: | { + type: Server.SES + sesKey: string + sesAccessKey: string + sesRegion: string + } + | { + type: Server.SMTP; + host: string; + port: number + password: string; + username: string; + } previewEmail: boolean retryAttempts?: number - server: Server - sesKey?: string - sesAccessKey?: string - sesRegion?: string + + templateDir: string templateEngine: | { diff --git a/src/lib/mailer/mailer.service.ts b/src/lib/mailer/mailer.service.ts index f0f14a38..db6114d0 100644 --- a/src/lib/mailer/mailer.service.ts +++ b/src/lib/mailer/mailer.service.ts @@ -55,13 +55,13 @@ export class MailerService { // create Nodemailer SES transporter - if (this.options.server === Server.SES) { + if (this.options.credentials.type === Server.SES) { const ses = new aws.SES({ apiVersion: "2010-12-01", - region: this.options.sesRegion, + region: this.options.credentials.sesRegion, credentials: { - accessKeyId: this.options.sesKey, - secretAccessKey: this.options.sesAccessKey, + accessKeyId: this.options.credentials.sesKey, + secretAccessKey: this.options.credentials.sesAccessKey, }, }); @@ -74,12 +74,12 @@ export class MailerService { this.transporter = createTransport({ pool: true, maxConnections: 5, - host: this.options.host, - port: this.options.port, + host: this.options.credentials.host, + port: this.options.credentials.port, secure: true, auth: { - user: this.options.username, - pass: this.options.password, + user: this.options.credentials.username, + pass: this.options.credentials.password, }, tls: { // do not fail on invalid certs diff --git a/src/lib/stripe.module.ts b/src/lib/stripe.module.ts index 8f5c3a4a..b42ca1eb 100644 --- a/src/lib/stripe.module.ts +++ b/src/lib/stripe.module.ts @@ -16,7 +16,7 @@ const logger = new Logger("Stripe"); logger, webhookConfig: { stripeSecrets: { - account: configService.get("stripe.account", { infer: true }), + account: configService.get("stripe.account", { infer: true })!, connect: configService.get("stripe.connect", { infer: true }), }, },