Skip to content

Commit a1c2914

Browse files
committed
feat: typesafe comparision decorator
1 parent 83aed2d commit a1c2914

File tree

5 files changed

+53
-62
lines changed

5 files changed

+53
-62
lines changed

.eslintrc.cjs

+45-45
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
// @ts-check
22
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
3-
const {defineConfig} = require("eslint-define-config");
3+
const { defineConfig } = require("eslint-define-config");
44

55
module.exports = defineConfig({
6-
parser: "@typescript-eslint/parser",
7-
parserOptions: {
8-
project: "tsconfig.json",
6+
parser: "@typescript-eslint/parser",
7+
parserOptions: {
8+
project: "tsconfig.json",
9+
},
10+
ignorePatterns: ["migrations", "src/generated", "**/*.spec.ts", "**/*.e2e.ts"], // optimize this
11+
extends: ["@rubiin/eslint-config-ts"],
12+
root: true,
13+
settings: {
14+
"import/resolver": {
15+
typescript: {
16+
alwaysTryTypes: true,
17+
project: "./tsconfig.json",
18+
},
919
},
10-
ignorePatterns: ["migrations", "src/generated", "**/*.spec.ts", "**/*.e2e.ts"], // optimize this
11-
extends: ["@rubiin/eslint-config-ts"],
12-
root: true,
13-
settings: {
14-
"import/resolver": {
15-
typescript: {
16-
alwaysTryTypes: true,
17-
project: "./tsconfig.json",
18-
},
19-
},
20-
},
21-
rules: {
22-
"unicorn/prefer-module": "off",
23-
"@typescript-eslint/no-floating-promises": "off",
24-
"no-useless-constructor": "off", // optimize this
25-
"@typescript-eslint/require-await": "off", // optimize this
26-
"@typescript-eslint/no-unsafe-assignment": "off", // optimize this
27-
"@typescript-eslint/no-unsafe-member-access": "off", // optimize this
28-
"unicorn/prefer-top-level-await": "off",
29-
"max-nested-callbacks": "off", // rxjs is nested
30-
"@typescript-eslint/no-misused-promises": [
31-
"error",
32-
{
33-
checksVoidReturn: false,
34-
},
35-
],
36-
"unicorn/prevent-abbreviations": [
37-
"error",
38-
{
39-
ignore: [
40-
"\\.e2e*",
41-
"\\.spec*",
42-
"\\.decorator*",
43-
"\\*idx*",
44-
],
45-
allowList: {
46-
ProcessEnv: true,
47-
UUIDParam: true,
48-
},
49-
},
20+
},
21+
rules: {
22+
"unicorn/prefer-module": "off",
23+
"@typescript-eslint/no-floating-promises": "off",
24+
"no-useless-constructor": "off", // optimize this
25+
"@typescript-eslint/require-await": "off", // optimize this
26+
"@typescript-eslint/no-unsafe-assignment": "off", // optimize this
27+
"@typescript-eslint/no-unsafe-member-access": "off", // optimize this
28+
"unicorn/prefer-top-level-await": "off",
29+
"max-nested-callbacks": "off", // rxjs is nested
30+
"@typescript-eslint/no-misused-promises": [
31+
"error",
32+
{
33+
checksVoidReturn: false,
34+
},
35+
],
36+
"unicorn/prevent-abbreviations": [
37+
"error",
38+
{
39+
ignore: [
40+
"\\.e2e*",
41+
"\\.spec*",
42+
"\\.decorator*",
43+
"\\*idx*",
5044
],
51-
},
45+
allowList: {
46+
ProcessEnv: true,
47+
UUIDParam: true,
48+
},
49+
},
50+
],
51+
},
5252
});

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class IsAfterConstraint implements ValidatorConstraintInterface {
2626
}
2727
}
2828

29-
export const IsAfter = (
30-
property: string,
29+
export const IsAfterField = <T = any>(
30+
property: keyof T,
3131
validationOptions?: ValidationOptions,
3232
): PropertyDecorator => {
3333
return function (object: Record<string, any>, propertyName: string | symbol) {
@@ -42,13 +42,3 @@ export const IsAfter = (
4242
};
4343

4444

45-
// // add typesafe property string
46-
47-
// export const IsAfterField = <T>(property: keyof T, validationOptions?: ValidationOptions) => {
48-
// return applyDecorators(
49-
// IsNotEmpty({
50-
// message: validationI18nMessage("validation.isNotEmpty"),
51-
// }),
52-
// IsAfter(String(property), validationOptions),
53-
// );
54-
// };

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class IsEqualToConstraint implements ValidatorConstraintInterface {
2525
}
2626
}
2727

28-
export const IsEqualToField = (
29-
property: string,
28+
export const IsEqualToField = <T = any>(
29+
property: keyof T,
3030
validationOptions?: ValidationOptions,
3131
): PropertyDecorator => {
3232
return function (object: Record<string, any>, propertyName: string | symbol) {
@@ -39,3 +39,5 @@ export const IsEqualToField = (
3939
});
4040
};
4141
};
42+
43+

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class IsGreaterThanConstraint implements ValidatorConstraintInterface {
2525
}
2626
}
2727

28-
export const IsGreaterThan = (
29-
property: string,
28+
export const IsGreaterThan = <T = any>(
29+
property: keyof T,
3030
validationOptions?: ValidationOptions,
3131
): PropertyDecorator => {
3232
return function (object: Record<string, any>, propertyName: string | symbol) {

tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"compilerOptions": {
44
"baseUrl": "src",
55
"outDir": "dist",
6-
"esModuleInterop": true,
76
"paths": {
87
"@lib/*": [
98
"./lib/*"

0 commit comments

Comments
 (0)