-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from boostcampwm-2022/feat/validation
feat: class-validator & class-transformer ์ ์ฉ
- Loading branch information
Showing
7 changed files
with
84 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
registerDecorator, | ||
ValidationOptions, | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
} from "class-validator"; | ||
|
||
@ValidatorConstraint({ name: "isValidId", async: false }) | ||
class isValidIdConstraint implements ValidatorConstraintInterface { | ||
public validate(value: string) { | ||
return ( | ||
typeof value === "string" && value.length >= 6 && value.length <= 20 && value.search(/^[a-zA-Z0-9]*$/) >= 0 | ||
); | ||
} | ||
|
||
public defaultMessage(): string { | ||
return `user id must be between 6 and 20 character long, only letters and numbers allowed`; | ||
} | ||
} | ||
|
||
export function IsValidId(validationOptions?: ValidationOptions) { | ||
return function (object: any, propertyName: string) { | ||
registerDecorator({ | ||
name: "isValidId", | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
constraints: [], | ||
options: validationOptions, | ||
validator: isValidIdConstraint, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { IsValidId } from "./id.validator"; | ||
import { IsValidPassword } from "./pw.validator"; | ||
|
||
export { IsValidId, IsValidPassword }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
registerDecorator, | ||
ValidationOptions, | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
} from "class-validator"; | ||
|
||
@ValidatorConstraint({ name: "isValidPassword", async: false }) | ||
class isValidPwConstraint implements ValidatorConstraintInterface { | ||
public validate(value: string) { | ||
return typeof value === "string" && value.length >= 10 && value.length <= 100; | ||
} | ||
|
||
public defaultMessage(): string { | ||
return `user password must be between 10 and 100 character long`; | ||
} | ||
} | ||
|
||
export function IsValidPassword(validationOptions?: ValidationOptions) { | ||
return function (object: any, propertyName: string) { | ||
registerDecorator({ | ||
name: "isValidPassword", | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
constraints: [], | ||
options: validationOptions, | ||
validator: isValidPwConstraint, | ||
}); | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters