From c695f624866d4f8458e0e6970d999b61926bfe1d Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 11 Oct 2023 12:54:55 +0545 Subject: [PATCH] fix: convert promises to async --- package.json | 6 +-- pnpm-lock.yaml | 39 +++++++++++++------ src/cluster.ts | 7 +++- src/common/@types/classes/offset.response.ts | 2 +- src/common/@types/enums/misc.enum.ts | 1 - .../validation/is-after.validator.spec.ts | 29 +++++++------- .../is-date-format.validator.spec.ts | 14 +++---- .../validation/is-equal-to.validator.spec.ts | 18 ++++----- .../is-greater-than.validator.spec.ts | 29 +++++++------- .../validation/is-password.validator.spec.ts | 23 +++++------ .../validation/is-profane.validator.spec.ts | 18 ++++----- .../validation/is-username.validator.spec.ts | 22 +++++------ src/common/helpers/app.utils.ts | 6 +-- src/common/misc/pool.ts | 12 ++---- src/common/misc/workers.ts | 2 - src/lib/config/configs/mail.config.ts | 1 - src/lib/mailer/mailer.service.ts | 7 +++- src/main.ts | 19 +++++---- src/repl.ts | 7 +++- test/e2e/post.e2e-spec.ts | 9 ++--- test/e2e/user.e2e-spec.ts | 9 ++--- tsconfig.json | 1 + 22 files changed, 141 insertions(+), 140 deletions(-) diff --git a/package.json b/package.json index 273c213d..63dddf6b 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ }, "scripts": { "build": "nest build", - "lint": "eslint --cache", - "lint:fix": "eslint --cache --fix", + "lint": "ESLINT_USE_FLAT_CONFIG=true eslint '{src,test}/**/*.ts' --cache", + "lint:fix": "ESLINT_USE_FLAT_CONFIG=true eslint '{src,test}/**/*.ts' --cache --fix", "orm": "npx mikro-orm", "sample": "cd env; npx sample-env --env .env.dev", "start": "nest start", @@ -147,7 +147,7 @@ "@nestjs/cli": "10.1.18", "@nestjs/schematics": "10.0.2", "@nestjs/testing": "10.2.7", - "@rubiin/eslint-config": "^1.8.11", + "@rubiin/eslint-config": "^1.8.17", "@rubiin/tsconfig": "^1.1.0", "@sentry/types": "^7.73.0", "@side/jest-runtime": "^1.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7dedb0ff..85c8ab50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -281,8 +281,8 @@ devDependencies: specifier: 10.2.7 version: 10.2.7(@nestjs/common@10.2.7)(@nestjs/core@10.2.7)(@nestjs/platform-express@10.2.7) '@rubiin/eslint-config': - specifier: ^1.8.11 - version: 1.8.11(eslint@8.51.0)(typescript@5.2.2)(vitest@0.34.6) + specifier: ^1.8.17 + version: 1.8.17(eslint@8.51.0)(typescript@5.2.2)(vitest@0.34.6) '@rubiin/tsconfig': specifier: ^1.1.0 version: 1.1.0 @@ -3624,8 +3624,8 @@ packages: '@redis/client': 1.5.11 dev: false - /@rubiin/eslint-config@1.8.11(eslint@8.51.0)(typescript@5.2.2)(vitest@0.34.6): - resolution: {integrity: sha512-7KV2zp7SOoajRESpICtNcETFaRhtqCQ2LuiuWthNB0aQb7kt4P0fBQSDZvHe7pomLYV/Wj8qgKhBFQhrqXIprw==} + /@rubiin/eslint-config@1.8.17(eslint@8.51.0)(typescript@5.2.2)(vitest@0.34.6): + resolution: {integrity: sha512-BliqzrazDWtxoDLqwWgxldiLN/6fLH4MBabxa9z4cRx+jQpuzBMnJhBf6VTvhY3K1ekSEjV6PHcxu8opfrYx4Q==} peerDependencies: eslint: '>=8.0.0' dependencies: @@ -3636,8 +3636,8 @@ packages: '@typescript-eslint/utils': 6.7.4(eslint@8.51.0)(typescript@5.2.2) eslint: 8.51.0 eslint-config-flat-gitignore: 0.1.0 - eslint-define-config: 1.23.0 - eslint-plugin-antfu: 1.0.0-beta.11(eslint@8.51.0)(typescript@5.2.2) + eslint-define-config: 1.24.1 + eslint-plugin-antfu: 1.0.0-beta.12(eslint@8.51.0)(typescript@5.2.2) eslint-plugin-eslint-comments: 3.2.0(eslint@8.51.0) eslint-plugin-i: 2.28.1(@typescript-eslint/parser@6.7.4)(eslint@8.51.0) eslint-plugin-jsdoc: 46.8.2(eslint@8.51.0) @@ -3647,6 +3647,7 @@ packages: eslint-plugin-no-only-tests: 3.1.0 eslint-plugin-react: 7.33.2(eslint@8.51.0) eslint-plugin-react-hooks: 4.6.0(eslint@8.51.0) + eslint-plugin-rubiin: 1.8.17(eslint@8.51.0)(typescript@5.2.2) eslint-plugin-unicorn: 48.0.1(eslint@8.51.0) eslint-plugin-unused-imports: 3.0.0(@typescript-eslint/eslint-plugin@6.7.4)(eslint@8.51.0) eslint-plugin-vitest: 0.3.2(@typescript-eslint/eslint-plugin@6.7.4)(eslint@8.51.0)(typescript@5.2.2)(vitest@0.34.6) @@ -7207,9 +7208,9 @@ packages: parse-gitignore: 2.0.0 dev: true - /eslint-define-config@1.23.0: - resolution: {integrity: sha512-4mMyu0JuBkQHsCtR+42irIQdFLmLIW+pMAVcyOV/gZRL4O1R8iuH0eMG3oL3Cbi1eo9fDAfT5CIHVHgdyxcf6w==} - engines: {node: ^16.13.0 || >=18.0.0, npm: '>=7.0.0', pnpm: '>= 8.6.0'} + /eslint-define-config@1.24.1: + resolution: {integrity: sha512-o36vBhPSWyIQlHoMqGhhcGmOOm2A2ccBVIdLTG/AWdm9YmjpsLpf+5ntf9LlHR6dduLREgxtGwvwPwSt7vnXJg==} + engines: {node: '>=18.0.0', npm: '>=9.0.0', pnpm: '>= 8.6.0'} dev: true /eslint-import-resolver-node@0.3.9: @@ -7251,12 +7252,14 @@ packages: - supports-color dev: true - /eslint-plugin-antfu@1.0.0-beta.11(eslint@8.51.0)(typescript@5.2.2): - resolution: {integrity: sha512-PxokjP4Ug6Cfpy49NZ+6f88zIoFzZFXUPdDcf6p6zog+0TxeDIA4QO1CRRiZFw2Mglloh2JzN+Y1NqeEyNz2oQ==} + /eslint-plugin-antfu@1.0.0-beta.12(eslint@8.51.0)(typescript@5.2.2): + resolution: {integrity: sha512-vPe0vigzDMmStU/hSZLAXfe6vdc26bOaxQt1a92tuOp3jkp0iT3/VXKlkMxsD9XTV/UL8/SNNTprMOUABC1vhQ==} + peerDependencies: + eslint: '*' dependencies: '@typescript-eslint/utils': 6.7.4(eslint@8.51.0)(typescript@5.2.2) + eslint: 8.51.0 transitivePeerDependencies: - - eslint - supports-color - typescript dev: true @@ -7408,6 +7411,18 @@ packages: string.prototype.matchall: 4.0.10 dev: true + /eslint-plugin-rubiin@1.8.17(eslint@8.51.0)(typescript@5.2.2): + resolution: {integrity: sha512-s5S8vPstNPpmn58K2elw4oWEtqHU1wHubdTnhjG3Q9xRd58bNRo06g/wom+kovYULqgJEDO3PJegH6yUjtDGbw==} + peerDependencies: + eslint: '*' + dependencies: + '@typescript-eslint/utils': 6.7.4(eslint@8.51.0)(typescript@5.2.2) + eslint: 8.51.0 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + /eslint-plugin-unicorn@48.0.1(eslint@8.51.0): resolution: {integrity: sha512-FW+4r20myG/DqFcCSzoumaddKBicIPeFnTrifon2mWIzlfyvzwyqZjqVP7m4Cqr/ZYisS2aiLghkUWaPg6vtCw==} engines: {node: '>=16'} diff --git a/src/cluster.ts b/src/cluster.ts index 255d8653..1a10c31c 100644 --- a/src/cluster.ts +++ b/src/cluster.ts @@ -27,9 +27,12 @@ export class Cluster { }); } else { - main().catch((error: Error) => { + try { + main(); + } + catch (error) { this.loggerService.error(error); - }); + } } } diff --git a/src/common/@types/classes/offset.response.ts b/src/common/@types/classes/offset.response.ts index 0518afb2..e95eeee2 100644 --- a/src/common/@types/classes/offset.response.ts +++ b/src/common/@types/classes/offset.response.ts @@ -44,7 +44,7 @@ export class OffsetMeta { pageOptionsDto, itemCount, }: { - pageOptionsDto: Omit + pageOptionsDto: Omit itemCount: number }) { this.page = pageOptionsDto.page; diff --git a/src/common/@types/enums/misc.enum.ts b/src/common/@types/enums/misc.enum.ts index 19fe8be1..d665490e 100644 --- a/src/common/@types/enums/misc.enum.ts +++ b/src/common/@types/enums/misc.enum.ts @@ -37,7 +37,6 @@ export enum TemplateEngine { HBS = "HBS", } - export const FileType: Record = { IMAGE: /(jpg|jpeg|png|gif|svg)$/i, DOC: /(pdf|doc|txt|key|csv|docx|xls|xlsx|ppt|pptx)$/i, diff --git a/src/common/decorators/validation/is-after.validator.spec.ts b/src/common/decorators/validation/is-after.validator.spec.ts index 3da894e2..e65e6207 100644 --- a/src/common/decorators/validation/is-after.validator.spec.ts +++ b/src/common/decorators/validation/is-after.validator.spec.ts @@ -11,42 +11,39 @@ describe("isAfter", () => { endDate!: Date; } - it("if endDate is after than startDate then it should succeed", () => { + it("if endDate is after than startDate then it should succeed", async () => { const model = new MyClass(); model.startDate = new Date("2022-02-21"); model.endDate = new Date("2022-05-01"); - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(0); - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(0); }); - it("if endDate is not after than startDate then it should fail", () => { + it("if endDate is not after than startDate then it should fail", async () => { const model = new MyClass(); model.startDate = new Date("2022-02-21"); model.endDate = new Date("2022-01-01"); - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - expect(errors[0].constraints).toEqual({ - IsAfterConstraint: "endDate should be after startDate", - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); + expect(errors[0].constraints).toEqual({ + IsAfterConstraint: "endDate should be after startDate", }); }); - it("if endDate is equal to startDate then it should fail", () => { + it("if endDate is equal to startDate then it should fail", async () => { const model = new MyClass(); model.startDate = new Date("2022-02-21"); model.endDate = model.startDate; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - expect(errors[0].constraints).toEqual({ - IsAfterConstraint: "endDate should be after startDate", - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); + expect(errors[0].constraints).toEqual({ + IsAfterConstraint: "endDate should be after startDate", }); }); }); diff --git a/src/common/decorators/validation/is-date-format.validator.spec.ts b/src/common/decorators/validation/is-date-format.validator.spec.ts index 79a00f40..9c871af6 100644 --- a/src/common/decorators/validation/is-date-format.validator.spec.ts +++ b/src/common/decorators/validation/is-date-format.validator.spec.ts @@ -9,23 +9,21 @@ describe("isDateInFormat", () => { date: string; } - it("if date satisfies the format then it should succeed", () => { + it("if date satisfies the format then it should succeed", async () => { const model = new MyClass(); model.date = "2014-04-03"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(0); - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(0); }); - it("if date does not satisfies the format then it should fail", () => { + it("if date does not satisfies the format then it should fail", async () => { const model = new MyClass(); model.date = "2014/04/03"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); }); }); diff --git a/src/common/decorators/validation/is-equal-to.validator.spec.ts b/src/common/decorators/validation/is-equal-to.validator.spec.ts index e55e2b32..04563ebb 100644 --- a/src/common/decorators/validation/is-equal-to.validator.spec.ts +++ b/src/common/decorators/validation/is-equal-to.validator.spec.ts @@ -11,28 +11,26 @@ describe("isEqualToField", () => { confirmPassword!: string; } - it("if password and confirm password are same then it should succeed", () => { + it("if password and confirm password are same then it should succeed", async () => { const model = new MyClass(); model.password = "Test@1234"; model.confirmPassword = "Test@1234"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(0); - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(0); }); - it("if password and confirm password are not same then it should fail", () => { + it("if password and confirm password are not same then it should fail", async () => { const model = new MyClass(); model.password = "UniquePassword@123"; model.confirmPassword = "DifferentPassword@1234"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - expect(errors[0].constraints).toEqual({ - IsEqualToConstraint: "confirmPassword should be equal to password", - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); + expect(errors[0].constraints).toEqual({ + IsEqualToConstraint: "confirmPassword should be equal to password", }); }); }); diff --git a/src/common/decorators/validation/is-greater-than.validator.spec.ts b/src/common/decorators/validation/is-greater-than.validator.spec.ts index 1620fba2..79dea297 100644 --- a/src/common/decorators/validation/is-greater-than.validator.spec.ts +++ b/src/common/decorators/validation/is-greater-than.validator.spec.ts @@ -11,42 +11,39 @@ describe("isGreaterThan", () => { totalMarks!: number; } - it("if totalMarks is greater than passMarks then it should succeed", () => { + it("if totalMarks is greater than passMarks then it should succeed", async () => { const model = new MyClass(); model.passMarks = 40; model.totalMarks = 100; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(0); - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(0); }); - it("if totalMarks is less than passMarks then it should fail", () => { + it("if totalMarks is less than passMarks then it should fail", async () => { const model = new MyClass(); model.passMarks = 100; model.totalMarks = 40; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - expect(errors[0].constraints).toEqual({ - IsGreaterThanConstraint: "totalMarks should be greater than passMarks", - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); + expect(errors[0].constraints).toEqual({ + IsGreaterThanConstraint: "totalMarks should be greater than passMarks", }); }); - it("if totalMarks is equal to passMarks then it should fail", () => { + it("if totalMarks is equal to passMarks then it should fail", async () => { const model = new MyClass(); model.passMarks = 100; model.totalMarks = 100; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - expect(errors[0].constraints).toEqual({ - IsGreaterThanConstraint: "totalMarks should be greater than passMarks", - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); + expect(errors[0].constraints).toEqual({ + IsGreaterThanConstraint: "totalMarks should be greater than passMarks", }); }); }); diff --git a/src/common/decorators/validation/is-password.validator.spec.ts b/src/common/decorators/validation/is-password.validator.spec.ts index 4a6fab87..ed141608 100644 --- a/src/common/decorators/validation/is-password.validator.spec.ts +++ b/src/common/decorators/validation/is-password.validator.spec.ts @@ -9,29 +9,26 @@ describe("isPassword", () => { password: string; } - it("if password satisfies then it should succeed (one uppercase,one lowercase, one number and one symbol and more than 8 characters)", () => { + it("if password satisfies then it should succeed (one uppercase,one lowercase, one number and one symbol and more than 8 characters)", async () => { const model = new MyClass(); model.password = "Test-1234"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(0); - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(0); }); - it("if password is not valid then it should fail", () => { + it("if password is not valid then it should fail", async () => { const model = new MyClass(); model.password = "notStrongPassword"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - expect(errors[0].property).toEqual("password"); - expect(errors[0].constraints).toEqual({ - IsPasswordConstraint: - "password should contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character", - }); - expect(errors[0].value).toEqual("notStrongPassword"); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); + expect(errors[0].property).toEqual("password"); + expect(errors[0].constraints).toEqual({ + IsPasswordConstraint: "password should contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character", }); + expect(errors[0].value).toEqual("notStrongPassword"); }); }); diff --git a/src/common/decorators/validation/is-profane.validator.spec.ts b/src/common/decorators/validation/is-profane.validator.spec.ts index f5fe2f30..bffbb528 100644 --- a/src/common/decorators/validation/is-profane.validator.spec.ts +++ b/src/common/decorators/validation/is-profane.validator.spec.ts @@ -9,26 +9,24 @@ describe("isProfane", () => { text!: string; } - it("it should pass if text doesn't profane words", () => { + it("it should pass if text doesn't profane words", async () => { const model = new MyClass(); model.text = "clean text"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(0); - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(0); }); - it("it should fail if text has profane words", () => { + it("it should fail if text has profane words", async () => { const model = new MyClass(); model.text = "Don't be an ash0le"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - expect(errors[0].constraints).toEqual({ - IsProfaneConstraint: "text has profane words", - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); + expect(errors[0].constraints).toEqual({ + IsProfaneConstraint: "text has profane words", }); }); }); diff --git a/src/common/decorators/validation/is-username.validator.spec.ts b/src/common/decorators/validation/is-username.validator.spec.ts index 75fe74f3..a6d90789 100644 --- a/src/common/decorators/validation/is-username.validator.spec.ts +++ b/src/common/decorators/validation/is-username.validator.spec.ts @@ -9,28 +9,26 @@ describe("isUserName", () => { username: string; } - it("if username satisfies then it should succeed", () => { + it("if username satisfies then it should succeed", async () => { const model = new MyClass(); model.username = "username123"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(0); - }); + const errors = await validator.validate(model); + expect(errors.length).toEqual(0); }); - it("if username is not valid then it should fail", () => { + it("if username is not valid then it should fail", async () => { const model = new MyClass(); model.username = "@123Yest"; - return validator.validate(model).then((errors) => { - expect(errors.length).toEqual(1); - expect(errors[0].property).toEqual("username"); - expect(errors[0].constraints).toEqual({ - IsUsernameConstraint: "username must fulfill username's criteria", - }); - expect(errors[0].value).toEqual("@123Yest"); + const errors = await validator.validate(model); + expect(errors.length).toEqual(1); + expect(errors[0].property).toEqual("username"); + expect(errors[0].constraints).toEqual({ + IsUsernameConstraint: "username must fulfill username's criteria", }); + expect(errors[0].value).toEqual("@123Yest"); }); }); diff --git a/src/common/helpers/app.utils.ts b/src/common/helpers/app.utils.ts index 5202c7db..cef4d3cb 100644 --- a/src/common/helpers/app.utils.ts +++ b/src/common/helpers/app.utils.ts @@ -30,7 +30,7 @@ export const AppUtils = { }; }, - gracefulShutdown(app: INestApplication, code: string): void { + gracefulShutdown(app: INestApplication, code: string) { setTimeout(() => process.exit(1), 5000); logger.verbose(`Signal received with code ${code} ⚡.`); logger.log("❗Closing http server with grace."); @@ -44,7 +44,7 @@ export const AppUtils = { }); }, - killAppWithGrace(app: INestApplication): void { + killAppWithGrace(app: INestApplication) { process.on("SIGINT", () => { AppUtils.gracefulShutdown(app, "SIGINT"); }); @@ -54,7 +54,7 @@ export const AppUtils = { }); }, - setupSwagger(app: INestApplication, configService: ConfigService): void { + setupSwagger(app: INestApplication, configService: ConfigService) { const userName = configService.get("app.swaggerUser", { infer: true }); const passWord = configService.get("app.swaggerPass", { infer: true }); const appName = configService.get("app.name", { infer: true }); diff --git a/src/common/misc/pool.ts b/src/common/misc/pool.ts index 26ab17bf..44fc768a 100644 --- a/src/common/misc/pool.ts +++ b/src/common/misc/pool.ts @@ -5,24 +5,20 @@ import { DynamicThreadPool, PoolEvents, availableParallelism } from "poolifier"; const logger = new Logger("ThreadPool"); - const workerFile = path.join( __dirname, - `workers${path.extname(__filename)}` + `workers${path.extname(__filename)}`, ); - /* Creating a new thread pool with half of available threads and a maximum of available threads. */ export const pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), availableParallelism(), workerFile, { enableTasksQueue: true, tasksQueueOptions: { - concurrency: 8 + concurrency: 8, }, errorHandler: error => logger.error(error), onlineHandler: () => logger.log("✅ Worker is online"), -}) - - +}); -pool.emitter?.on(PoolEvents.ready, () => logger.log('✅ Pool is ready')); +pool.emitter?.on(PoolEvents.ready, () => logger.log("✅ Pool is ready")); pool.emitter?.on(PoolEvents.busy, () => logger.log("🔵 Pool is busy")); diff --git a/src/common/misc/workers.ts b/src/common/misc/workers.ts index 126b9e79..7c54e0e2 100644 --- a/src/common/misc/workers.ts +++ b/src/common/misc/workers.ts @@ -2,8 +2,6 @@ import { ThreadWorker } from "poolifier"; import { HelperService } from "@common/helpers"; import { ThreadFunctions } from "@common/@types"; - - // all expensive process goes here to avoid blocking the main thread function workerFunction(data: { functionName: string; input: string }) { switch (data.functionName) { diff --git a/src/lib/config/configs/mail.config.ts b/src/lib/config/configs/mail.config.ts index 0933354c..b88286a9 100644 --- a/src/lib/config/configs/mail.config.ts +++ b/src/lib/config/configs/mail.config.ts @@ -1,4 +1,3 @@ -/* eslint-disable unicorn/no-thenable */ import { registerAs } from "@nestjs/config"; import Joi from "joi"; import { SES_REGIONS } from "@common/constant"; diff --git a/src/lib/mailer/mailer.service.ts b/src/lib/mailer/mailer.service.ts index 86e191d4..f0f14a38 100644 --- a/src/lib/mailer/mailer.service.ts +++ b/src/lib/mailer/mailer.service.ts @@ -102,9 +102,12 @@ export class MailerService { mailOptions.html = html; if (this.options.previewEmail === true) { - previewEmail(mailOptions).catch((error) => { + try { + previewEmail(mailOptions); + } + catch (error) { this.logger.error(error); - }); + } } return from(this.transporter.sendMail(mailOptions)).pipe( diff --git a/src/main.ts b/src/main.ts index 9d0596a4..c4fda59d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,7 +52,7 @@ async function bootstrap() { app.use(helmet()); app.enableCors({ credentials: true, - methods: ["GET","HEAD","PUT","PATCH","POST","DELETE","OPTIONS"], + methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE", "OPTIONS"], maxAge: 3600, origin: configService.get("app.allowedOrigins", { infer: true }), }); @@ -72,7 +72,6 @@ async function bootstrap() { app.useGlobalInterceptors(new LoggerErrorInterceptor()); - // ========================================================= // configure socket // ========================================================= @@ -102,12 +101,12 @@ async function bootstrap() { await app.listen(port); logger.log( - `🚀 Application is running on: ${chalk.green(`http://localhost:${port}/${globalPrefix}`)}`, + `🚀 Application is running on: ${chalk.green(`http://localhost:${port}/${globalPrefix}`)}`, ); logger.log( - `🚦 Accepting request only from: ${chalk.green( - `${configService.get("app.allowedOrigins", { infer: true }).toString()}`, - )}`, + `🚦 Accepting request only from: ${chalk.green( + `${configService.get("app.allowedOrigins", { infer: true }).toString()}`, + )}`, ); !HelperService.isProd() @@ -115,6 +114,10 @@ async function bootstrap() { logger.log(`Server is up. ${chalk.yellow(`+${Math.trunc(performance.now())}ms`)}`); } -(async () => await bootstrap())().catch((error) => { +try { + ~(async () => await bootstrap())(); +} + +catch (error) { logger.error(error); -}); +} diff --git a/src/repl.ts b/src/repl.ts index effd8ace..a6146442 100644 --- a/src/repl.ts +++ b/src/repl.ts @@ -25,6 +25,9 @@ async function bootstrap() { }); } -(async () => await bootstrap())().catch((error) => { +try { + (async () => await bootstrap())(); +} +catch (error) { logger.error(error); -}); +} diff --git a/test/e2e/post.e2e-spec.ts b/test/e2e/post.e2e-spec.ts index 9ddc7634..b98f8911 100644 --- a/test/e2e/post.e2e-spec.ts +++ b/test/e2e/post.e2e-spec.ts @@ -10,12 +10,11 @@ describe("PostController (e2e)", () => { const app = APP_URL; beforeAll(async () => { - return request(app) + const { body } = await request(app) .post("/auth/login") - .send(user.admin) - .then(({ body }) => { - adminJwtToken = body.payload.accessToken; - }); + .send(user.admin); + + adminJwtToken = body.payload.accessToken; }); describe("Post", () => { diff --git a/test/e2e/user.e2e-spec.ts b/test/e2e/user.e2e-spec.ts index abbe058c..c07f9f72 100644 --- a/test/e2e/user.e2e-spec.ts +++ b/test/e2e/user.e2e-spec.ts @@ -14,12 +14,11 @@ describe("UserController (e2e)", () => { const app = APP_URL; beforeAll(async () => { - return request(app) + const { body } = await request(app) .post("/auth/login") - .send(user.admin) - .then(({ body }) => { - adminJwtToken = body.payload.accessToken; - }); + .send(user.admin); + + adminJwtToken = body.payload.accessToken; }); describe("User", () => { diff --git a/tsconfig.json b/tsconfig.json index 8723054b..74f6e7ff 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,6 +25,7 @@ "outDir": "dist" }, "include": [ + "test/**/*", "src/**/*", "eslint.config.js" ],