feat: add field validators for username and password, and integrate them into DTOs
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { Matches, MinLength } from 'class-validator'
|
||||
|
||||
const MIN_LENGTH = 6
|
||||
const REGEX = /^[a-zA-Z0-9]*$/
|
||||
|
||||
export const FiscalIdFieldValidator = () =>
|
||||
function (target: object, propertyKey: string) {
|
||||
MinLength(MIN_LENGTH, {
|
||||
message: `شناسه یکتا باید حداقل ${MIN_LENGTH} کاراکتر باشد`,
|
||||
})(target, propertyKey)
|
||||
Matches(REGEX, {
|
||||
message: 'شناسه یکتا فقط میتواند شامل حروف و اعداد باشد',
|
||||
})(target, propertyKey)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export { FiscalIdFieldValidator } from './fiscalId-validator'
|
||||
export { PasswordFieldValidator, PASSWORD_MIN_LENGTH } from './password'
|
||||
export { UsernameFieldValidator } from './username'
|
||||
@@ -0,0 +1,10 @@
|
||||
import { MinLength } from 'class-validator'
|
||||
|
||||
export const PASSWORD_MIN_LENGTH = 6
|
||||
|
||||
export const PasswordFieldValidator = () =>
|
||||
function (target: object, propertyKey: string) {
|
||||
MinLength(PASSWORD_MIN_LENGTH, {
|
||||
message: `رمز عبور باید حداقل ${PASSWORD_MIN_LENGTH} کاراکتر باشد`,
|
||||
})(target, propertyKey)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Matches, MinLength } from 'class-validator'
|
||||
|
||||
const USERNAME_REGEX = /^[a-zA-Z0-9_-]*$/
|
||||
const USERNAME_MIN_LENGTH = 6
|
||||
|
||||
export const UsernameFieldValidator = () =>
|
||||
function (target: object, propertyKey: string) {
|
||||
MinLength(USERNAME_MIN_LENGTH, {
|
||||
message: `نام کاربری باید حداقل ${USERNAME_MIN_LENGTH} کاراکتر باشد`,
|
||||
})(target, propertyKey)
|
||||
Matches(USERNAME_REGEX, {
|
||||
message: 'نام کاربری فقط میتواند شامل حروف، اعداد، زیرخط و خط تیره باشد',
|
||||
})(target, propertyKey)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './enum-translator.util'
|
||||
export * from './field-validator.util'
|
||||
export * from './http-client.util'
|
||||
export * from './jwt-user.util'
|
||||
export * from './mappers/consumer_mappers.util'
|
||||
|
||||
Reference in New Issue
Block a user