Skip to content

Commit

Permalink
feat: typesafe comparision decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Sep 25, 2023
1 parent 83aed2d commit a1c2914
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 62 deletions.
90 changes: 45 additions & 45 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
// @ts-check
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const {defineConfig} = require("eslint-define-config");
const { defineConfig } = require("eslint-define-config");

module.exports = defineConfig({
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
},
ignorePatterns: ["migrations", "src/generated", "**/*.spec.ts", "**/*.e2e.ts"], // optimize this
extends: ["@rubiin/eslint-config-ts"],
root: true,
settings: {
"import/resolver": {
typescript: {
alwaysTryTypes: true,
project: "./tsconfig.json",
},
},
ignorePatterns: ["migrations", "src/generated", "**/*.spec.ts", "**/*.e2e.ts"], // optimize this
extends: ["@rubiin/eslint-config-ts"],
root: true,
settings: {
"import/resolver": {
typescript: {
alwaysTryTypes: true,
project: "./tsconfig.json",
},
},
},
rules: {
"unicorn/prefer-module": "off",
"@typescript-eslint/no-floating-promises": "off",
"no-useless-constructor": "off", // optimize this
"@typescript-eslint/require-await": "off", // optimize this
"@typescript-eslint/no-unsafe-assignment": "off", // optimize this
"@typescript-eslint/no-unsafe-member-access": "off", // optimize this
"unicorn/prefer-top-level-await": "off",
"max-nested-callbacks": "off", // rxjs is nested
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: false,
},
],
"unicorn/prevent-abbreviations": [
"error",
{
ignore: [
"\\.e2e*",
"\\.spec*",
"\\.decorator*",
"\\*idx*",
],
allowList: {
ProcessEnv: true,
UUIDParam: true,
},
},
},
rules: {
"unicorn/prefer-module": "off",
"@typescript-eslint/no-floating-promises": "off",
"no-useless-constructor": "off", // optimize this
"@typescript-eslint/require-await": "off", // optimize this
"@typescript-eslint/no-unsafe-assignment": "off", // optimize this
"@typescript-eslint/no-unsafe-member-access": "off", // optimize this
"unicorn/prefer-top-level-await": "off",
"max-nested-callbacks": "off", // rxjs is nested
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: false,
},
],
"unicorn/prevent-abbreviations": [
"error",
{
ignore: [
"\\.e2e*",
"\\.spec*",
"\\.decorator*",
"\\*idx*",
],
},
allowList: {
ProcessEnv: true,
UUIDParam: true,
},
},
],
},
});
14 changes: 2 additions & 12 deletions src/common/decorators/validation/is-after.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IsAfterConstraint implements ValidatorConstraintInterface {
}
}

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


// // add typesafe property string

// export const IsAfterField = <T>(property: keyof T, validationOptions?: ValidationOptions) => {
// return applyDecorators(
// IsNotEmpty({
// message: validationI18nMessage("validation.isNotEmpty"),
// }),
// IsAfter(String(property), validationOptions),
// );
// };
6 changes: 4 additions & 2 deletions src/common/decorators/validation/is-equal-to.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class IsEqualToConstraint implements ValidatorConstraintInterface {
}
}

export const IsEqualToField = (
property: string,
export const IsEqualToField = <T = any>(
property: keyof T,
validationOptions?: ValidationOptions,
): PropertyDecorator => {
return function (object: Record<string, any>, propertyName: string | symbol) {
Expand All @@ -39,3 +39,5 @@ export const IsEqualToField = (
});
};
};


4 changes: 2 additions & 2 deletions src/common/decorators/validation/is-greater-than.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class IsGreaterThanConstraint implements ValidatorConstraintInterface {
}
}

export const IsGreaterThan = (
property: string,
export const IsGreaterThan = <T = any>(
property: keyof T,
validationOptions?: ValidationOptions,
): PropertyDecorator => {
return function (object: Record<string, any>, propertyName: string | symbol) {
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist",
"esModuleInterop": true,
"paths": {
"@lib/*": [
"./lib/*"
Expand Down

0 comments on commit a1c2914

Please sign in to comment.