-
Notifications
You must be signed in to change notification settings - Fork 35
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 #118 from DigiChanges/feat/GC/NRS-43/validate-birt…
…hday-format feat: add custom validate to birthday user format
- Loading branch information
Showing
4 changed files
with
53 additions
and
7 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
yarn sync:db | ||
yarn command addUser --email [email protected] --firstName super --lastName admin --documentType DNI --documentNumber 12345679 --gender male --phone 541112345678 --country AR --address av.1234 --password 12345678 --birthday 05/07/1990 --isSuperAdmin true | ||
yarn command addUser --email [email protected] --firstName super --lastName admin --documentType DNI --documentNumber 12345679 --gender male --phone 541112345678 --country AR --address av.1234 --password 12345678 --birthday 1990-07-05 --isSuperAdmin true | ||
yarn command addUserRole --role Admin --email [email protected] --firstName node --lastName node --password 12345678 --documentType DNI --documentNumber 12345678 --gender male --phone 541112345678 --country AR --address av.1234 --isSuperAdmin false --birthday 04/07/1990 | ||
yarn command activeUser --email [email protected] | ||
yarn command activeUser --email [email protected] | ||
|
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,44 @@ | ||
import { ValidationOptions, ValidatorConstraint, ValidatorConstraintInterface, registerDecorator } from 'class-validator'; | ||
|
||
export function IsValidBirthday(validationOptions?: ValidationOptions) | ||
{ | ||
return (object: any, propertyName: string) => | ||
{ | ||
registerDecorator({ | ||
target: object.constructor, | ||
propertyName, | ||
options: validationOptions, | ||
validator: IsValidBirthdayConstraint | ||
}); | ||
}; | ||
} | ||
|
||
@ValidatorConstraint({ name: 'IsValidBirthday' }) | ||
class IsValidBirthdayConstraint implements ValidatorConstraintInterface | ||
{ | ||
public validate(date: string) | ||
{ | ||
return date ? this.dateIsValid(date) : false; | ||
} | ||
|
||
private dateIsValid(dateStr: string) | ||
{ | ||
const regex = /^\d{4}-\d{2}-\d{2}$/; | ||
|
||
if (dateStr.match(regex) === null) | ||
{ | ||
return false; | ||
} | ||
|
||
const date = new Date(dateStr); | ||
|
||
const timestamp = date.getTime(); | ||
|
||
if (typeof timestamp !== 'number' || Number.isNaN(timestamp)) | ||
{ | ||
return false; | ||
} | ||
|
||
return date.toISOString().startsWith(dateStr); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ describe('Start User Test', () => | |
firstName: 'Jhon', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
birthday: '04/08/1991', | ||
birthday: '1991-08-04', | ||
documentType: 'dni', | ||
documentNumber: '35319112', | ||
gender: 'male', | ||
|
@@ -83,7 +83,7 @@ describe('Start User Test', () => | |
firstName: 'Jhon', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
birthday: '04/08/1992', | ||
birthday: '1992-08-04', | ||
documentType: 'dni', | ||
documentNumber: '35319321', | ||
gender: 'male', | ||
|
@@ -142,7 +142,7 @@ describe('Start User Test', () => | |
firstName: 'Jhon Update', | ||
lastName: 'Doe Update', | ||
email: '[email protected]', | ||
birthday: '04/08/1991', | ||
birthday: '1991-08-04', | ||
documentType: 'dni', | ||
documentNumber: '35319131', | ||
gender: 'female', | ||
|
@@ -209,7 +209,7 @@ describe('Start User Test', () => | |
email: '[email protected]', | ||
firstName: 'Jhon for delete', | ||
lastName: 'Doe Update', | ||
birthday: '04/08/1992', | ||
birthday: '1992-08-04', | ||
documentType: 'dni', | ||
documentNumber: '25319112', | ||
gender: 'male', | ||
|
@@ -385,7 +385,7 @@ describe('Start User Test', () => | |
email: '[email protected]', | ||
firstName: 150, | ||
lastName: 'Doe 1', | ||
birthday: '04/07/1990', | ||
birthday: '1990-08-04', | ||
documentType: 'dni', | ||
documentNumber: '35319132', | ||
gender: 'male', | ||
|