Skip to content

Commit c695f62

Browse files
committed
fix: convert promises to async
1 parent 62fb6fd commit c695f62

22 files changed

+141
-140
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
},
3838
"scripts": {
3939
"build": "nest build",
40-
"lint": "eslint --cache",
41-
"lint:fix": "eslint --cache --fix",
40+
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint '{src,test}/**/*.ts' --cache",
41+
"lint:fix": "ESLINT_USE_FLAT_CONFIG=true eslint '{src,test}/**/*.ts' --cache --fix",
4242
"orm": "npx mikro-orm",
4343
"sample": "cd env; npx sample-env --env .env.dev",
4444
"start": "nest start",
@@ -147,7 +147,7 @@
147147
"@nestjs/cli": "10.1.18",
148148
"@nestjs/schematics": "10.0.2",
149149
"@nestjs/testing": "10.2.7",
150-
"@rubiin/eslint-config": "^1.8.11",
150+
"@rubiin/eslint-config": "^1.8.17",
151151
"@rubiin/tsconfig": "^1.1.0",
152152
"@sentry/types": "^7.73.0",
153153
"@side/jest-runtime": "^1.1.0",

pnpm-lock.yaml

+27-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cluster.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ export class Cluster {
2727
});
2828
}
2929
else {
30-
main().catch((error: Error) => {
30+
try {
31+
main();
32+
}
33+
catch (error) {
3134
this.loggerService.error(error);
32-
});
35+
}
3336
}
3437
}
3538

src/common/@types/classes/offset.response.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class OffsetMeta {
4444
pageOptionsDto,
4545
itemCount,
4646
}: {
47-
pageOptionsDto: Omit<OffsetPaginationDto,"type">
47+
pageOptionsDto: Omit<OffsetPaginationDto, "type">
4848
itemCount: number
4949
}) {
5050
this.page = pageOptionsDto.page;

src/common/@types/enums/misc.enum.ts

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export enum TemplateEngine {
3737
HBS = "HBS",
3838
}
3939

40-
4140
export const FileType: Record<keyof typeof FileSize, RegExp> = {
4241
IMAGE: /(jpg|jpeg|png|gif|svg)$/i,
4342
DOC: /(pdf|doc|txt|key|csv|docx|xls|xlsx|ppt|pptx)$/i,

src/common/decorators/validation/is-after.validator.spec.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,39 @@ describe("isAfter", () => {
1111
endDate!: Date;
1212
}
1313

14-
it("if endDate is after than startDate then it should succeed", () => {
14+
it("if endDate is after than startDate then it should succeed", async () => {
1515
const model = new MyClass();
1616

1717
model.startDate = new Date("2022-02-21");
1818
model.endDate = new Date("2022-05-01");
1919

20-
return validator.validate(model).then((errors) => {
21-
expect(errors.length).toEqual(0);
22-
});
20+
const errors = await validator.validate(model);
21+
expect(errors.length).toEqual(0);
2322
});
2423

25-
it("if endDate is not after than startDate then it should fail", () => {
24+
it("if endDate is not after than startDate then it should fail", async () => {
2625
const model = new MyClass();
2726

2827
model.startDate = new Date("2022-02-21");
2928
model.endDate = new Date("2022-01-01");
3029

31-
return validator.validate(model).then((errors) => {
32-
expect(errors.length).toEqual(1);
33-
expect(errors[0].constraints).toEqual({
34-
IsAfterConstraint: "endDate should be after startDate",
35-
});
30+
const errors = await validator.validate(model);
31+
expect(errors.length).toEqual(1);
32+
expect(errors[0].constraints).toEqual({
33+
IsAfterConstraint: "endDate should be after startDate",
3634
});
3735
});
3836

39-
it("if endDate is equal to startDate then it should fail", () => {
37+
it("if endDate is equal to startDate then it should fail", async () => {
4038
const model = new MyClass();
4139

4240
model.startDate = new Date("2022-02-21");
4341
model.endDate = model.startDate;
4442

45-
return validator.validate(model).then((errors) => {
46-
expect(errors.length).toEqual(1);
47-
expect(errors[0].constraints).toEqual({
48-
IsAfterConstraint: "endDate should be after startDate",
49-
});
43+
const errors = await validator.validate(model);
44+
expect(errors.length).toEqual(1);
45+
expect(errors[0].constraints).toEqual({
46+
IsAfterConstraint: "endDate should be after startDate",
5047
});
5148
});
5249
});

src/common/decorators/validation/is-date-format.validator.spec.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,21 @@ describe("isDateInFormat", () => {
99
date: string;
1010
}
1111

12-
it("if date satisfies the format then it should succeed", () => {
12+
it("if date satisfies the format then it should succeed", async () => {
1313
const model = new MyClass();
1414

1515
model.date = "2014-04-03";
1616

17-
return validator.validate(model).then((errors) => {
18-
expect(errors.length).toEqual(0);
19-
});
17+
const errors = await validator.validate(model);
18+
expect(errors.length).toEqual(0);
2019
});
2120

22-
it("if date does not satisfies the format then it should fail", () => {
21+
it("if date does not satisfies the format then it should fail", async () => {
2322
const model = new MyClass();
2423

2524
model.date = "2014/04/03";
2625

27-
return validator.validate(model).then((errors) => {
28-
expect(errors.length).toEqual(1);
29-
});
26+
const errors = await validator.validate(model);
27+
expect(errors.length).toEqual(1);
3028
});
3129
});

src/common/decorators/validation/is-equal-to.validator.spec.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,26 @@ describe("isEqualToField", () => {
1111
confirmPassword!: string;
1212
}
1313

14-
it("if password and confirm password are same then it should succeed", () => {
14+
it("if password and confirm password are same then it should succeed", async () => {
1515
const model = new MyClass();
1616

1717
model.password = "Test@1234";
1818
model.confirmPassword = "Test@1234";
1919

20-
return validator.validate(model).then((errors) => {
21-
expect(errors.length).toEqual(0);
22-
});
20+
const errors = await validator.validate(model);
21+
expect(errors.length).toEqual(0);
2322
});
2423

25-
it("if password and confirm password are not same then it should fail", () => {
24+
it("if password and confirm password are not same then it should fail", async () => {
2625
const model = new MyClass();
2726

2827
model.password = "UniquePassword@123";
2928
model.confirmPassword = "DifferentPassword@1234";
3029

31-
return validator.validate(model).then((errors) => {
32-
expect(errors.length).toEqual(1);
33-
expect(errors[0].constraints).toEqual({
34-
IsEqualToConstraint: "confirmPassword should be equal to password",
35-
});
30+
const errors = await validator.validate(model);
31+
expect(errors.length).toEqual(1);
32+
expect(errors[0].constraints).toEqual({
33+
IsEqualToConstraint: "confirmPassword should be equal to password",
3634
});
3735
});
3836
});

src/common/decorators/validation/is-greater-than.validator.spec.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,39 @@ describe("isGreaterThan", () => {
1111
totalMarks!: number;
1212
}
1313

14-
it("if totalMarks is greater than passMarks then it should succeed", () => {
14+
it("if totalMarks is greater than passMarks then it should succeed", async () => {
1515
const model = new MyClass();
1616

1717
model.passMarks = 40;
1818
model.totalMarks = 100;
1919

20-
return validator.validate(model).then((errors) => {
21-
expect(errors.length).toEqual(0);
22-
});
20+
const errors = await validator.validate(model);
21+
expect(errors.length).toEqual(0);
2322
});
2423

25-
it("if totalMarks is less than passMarks then it should fail", () => {
24+
it("if totalMarks is less than passMarks then it should fail", async () => {
2625
const model = new MyClass();
2726

2827
model.passMarks = 100;
2928
model.totalMarks = 40;
3029

31-
return validator.validate(model).then((errors) => {
32-
expect(errors.length).toEqual(1);
33-
expect(errors[0].constraints).toEqual({
34-
IsGreaterThanConstraint: "totalMarks should be greater than passMarks",
35-
});
30+
const errors = await validator.validate(model);
31+
expect(errors.length).toEqual(1);
32+
expect(errors[0].constraints).toEqual({
33+
IsGreaterThanConstraint: "totalMarks should be greater than passMarks",
3634
});
3735
});
3836

39-
it("if totalMarks is equal to passMarks then it should fail", () => {
37+
it("if totalMarks is equal to passMarks then it should fail", async () => {
4038
const model = new MyClass();
4139

4240
model.passMarks = 100;
4341
model.totalMarks = 100;
4442

45-
return validator.validate(model).then((errors) => {
46-
expect(errors.length).toEqual(1);
47-
expect(errors[0].constraints).toEqual({
48-
IsGreaterThanConstraint: "totalMarks should be greater than passMarks",
49-
});
43+
const errors = await validator.validate(model);
44+
expect(errors.length).toEqual(1);
45+
expect(errors[0].constraints).toEqual({
46+
IsGreaterThanConstraint: "totalMarks should be greater than passMarks",
5047
});
5148
});
5249
});

src/common/decorators/validation/is-password.validator.spec.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,26 @@ describe("isPassword", () => {
99
password: string;
1010
}
1111

12-
it("if password satisfies then it should succeed (one uppercase,one lowercase, one number and one symbol and more than 8 characters)", () => {
12+
it("if password satisfies then it should succeed (one uppercase,one lowercase, one number and one symbol and more than 8 characters)", async () => {
1313
const model = new MyClass();
1414

1515
model.password = "Test-1234";
1616

17-
return validator.validate(model).then((errors) => {
18-
expect(errors.length).toEqual(0);
19-
});
17+
const errors = await validator.validate(model);
18+
expect(errors.length).toEqual(0);
2019
});
2120

22-
it("if password is not valid then it should fail", () => {
21+
it("if password is not valid then it should fail", async () => {
2322
const model = new MyClass();
2423

2524
model.password = "notStrongPassword";
2625

27-
return validator.validate(model).then((errors) => {
28-
expect(errors.length).toEqual(1);
29-
expect(errors[0].property).toEqual("password");
30-
expect(errors[0].constraints).toEqual({
31-
IsPasswordConstraint:
32-
"password should contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character",
33-
});
34-
expect(errors[0].value).toEqual("notStrongPassword");
26+
const errors = await validator.validate(model);
27+
expect(errors.length).toEqual(1);
28+
expect(errors[0].property).toEqual("password");
29+
expect(errors[0].constraints).toEqual({
30+
IsPasswordConstraint: "password should contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character",
3531
});
32+
expect(errors[0].value).toEqual("notStrongPassword");
3633
});
3734
});

src/common/decorators/validation/is-profane.validator.spec.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@ describe("isProfane", () => {
99
text!: string;
1010
}
1111

12-
it("it should pass if text doesn't profane words", () => {
12+
it("it should pass if text doesn't profane words", async () => {
1313
const model = new MyClass();
1414

1515
model.text = "clean text";
1616

17-
return validator.validate(model).then((errors) => {
18-
expect(errors.length).toEqual(0);
19-
});
17+
const errors = await validator.validate(model);
18+
expect(errors.length).toEqual(0);
2019
});
2120

22-
it("it should fail if text has profane words", () => {
21+
it("it should fail if text has profane words", async () => {
2322
const model = new MyClass();
2423

2524
model.text = "Don't be an ash0le";
2625

27-
return validator.validate(model).then((errors) => {
28-
expect(errors.length).toEqual(1);
29-
expect(errors[0].constraints).toEqual({
30-
IsProfaneConstraint: "text has profane words",
31-
});
26+
const errors = await validator.validate(model);
27+
expect(errors.length).toEqual(1);
28+
expect(errors[0].constraints).toEqual({
29+
IsProfaneConstraint: "text has profane words",
3230
});
3331
});
3432
});

0 commit comments

Comments
 (0)