Skip to content

Commit

Permalink
fix: upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Oct 12, 2023
1 parent 4e79ea7 commit 5191e20
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}),
);
Expand Down
2 changes: 1 addition & 1 deletion src/common/misc/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};

Expand Down
4 changes: 4 additions & 0 deletions src/lib/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
redisConfigValidationSchema,
sentry,
sentryConfigurationValidationSchema,
stripe,
stripeonfigValidationSchema,
throttle,
throttleConfigValidationSchema,
} from "./configs";
Expand All @@ -42,6 +44,7 @@ import {
facebookOauth,
throttle,
sentry,
stripe
],
cache: true,
isGlobal: true,
Expand All @@ -57,6 +60,7 @@ import {
...facebookOauthConfigValidationSchema,
...throttleConfigValidationSchema,
...sentryConfigurationValidationSchema,
...stripeonfigValidationSchema
}),
validationOptions: {
abortEarly: true,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config/configs/mail.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/config/configs/stripe.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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(),
};

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,
}));
14 changes: 8 additions & 6 deletions src/lib/mailer/index.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -10,11 +10,13 @@ import { MailModule } from "./mailer.module";
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService<Configs, true>) => ({
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: {
Expand Down
24 changes: 16 additions & 8 deletions src/lib/mailer/mailer.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
| {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/mailer/mailer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stripe.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
},
},
Expand Down

0 comments on commit 5191e20

Please sign in to comment.