Skip to content

Commit

Permalink
adjust language for request, and ignore *.json file for cspell
Browse files Browse the repository at this point in the history
  • Loading branch information
andrechristikan committed Sep 8, 2023
1 parent 18c7bcf commit c25f56c
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 30 deletions.
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
".husky/**",
".github/**",
"dist/**",
"logs/**"
"logs/**",
"**/**/*.json"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ack-nestjs-boilerplate",
"version": "5.4.4",
"version": "5.4.5",
"description": "Ack NestJs Boilerplate",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { HelperDateService } from 'src/common/helper/services/helper.date.servic

@ValidatorConstraint({ async: true })
@Injectable()
export class MinDateTodayConstraint implements ValidatorConstraintInterface {
export class DateGreaterThanEqualTodayConstraint
implements ValidatorConstraintInterface
{
constructor(private readonly helperDateService: HelperDateService) {}

validate(value: string): boolean {
Expand All @@ -22,15 +24,17 @@ export class MinDateTodayConstraint implements ValidatorConstraintInterface {
}
}

export function MinDateToday(validationOptions?: ValidationOptions) {
export function DateGreaterThanEqualToday(
validationOptions?: ValidationOptions
) {
return function (object: Record<string, any>, propertyName: string): any {
registerDecorator({
name: 'MinDateToday',
name: 'DateGreaterThanEqualToday',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [],
validator: MinDateTodayConstraint,
validator: DateGreaterThanEqualTodayConstraint,
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { HelperDateService } from 'src/common/helper/services/helper.date.servic

@ValidatorConstraint({ async: true })
@Injectable()
export class MaxDateTodayConstraint implements ValidatorConstraintInterface {
export class DateLessThanEqualTodayConstraint
implements ValidatorConstraintInterface
{
constructor(private readonly helperDateService: HelperDateService) {}

validate(value: string): boolean {
Expand All @@ -21,15 +23,15 @@ export class MaxDateTodayConstraint implements ValidatorConstraintInterface {
}
}

export function MaxDateToday(validationOptions?: ValidationOptions) {
export function DateLessThanEqualToday(validationOptions?: ValidationOptions) {
return function (object: Record<string, any>, propertyName: string): any {
registerDecorator({
name: 'MaxDateToday',
name: 'DateLessThanEqualToday',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [],
validator: MaxDateTodayConstraint,
validator: DateLessThanEqualTodayConstraint,
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

@ValidatorConstraint({ async: true })
@Injectable()
export class MinGreaterThanEqualConstraint
export class GreaterThanEqualConstraint
implements ValidatorConstraintInterface
{
validate(value: string, args: ValidationArguments): boolean {
Expand All @@ -19,18 +19,18 @@ export class MinGreaterThanEqualConstraint
}
}

export function MinGreaterThanEqual(
export function GreaterThanEqual(
property: string,
validationOptions?: ValidationOptions
) {
return function (object: Record<string, any>, propertyName: string): void {
registerDecorator({
name: 'MinGreaterThanEqual',
name: 'GreaterThanEqual',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [property],
validator: MinGreaterThanEqualConstraint,
validator: GreaterThanEqualConstraint,
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import {

@ValidatorConstraint({ async: true })
@Injectable()
export class MinGreaterThanConstraint implements ValidatorConstraintInterface {
export class GreaterThanConstraint implements ValidatorConstraintInterface {
validate(value: string, args: ValidationArguments): boolean {
const [property] = args.constraints;
const relatedValue = args.object[property];
return value > relatedValue;
}
}

export function MinGreaterThan(
export function GreaterThan(
property: string,
validationOptions?: ValidationOptions
) {
return function (object: Record<string, any>, propertyName: string): void {
registerDecorator({
name: 'MinGreaterThan',
name: 'GreaterThan',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [property],
validator: MinGreaterThanConstraint,
validator: GreaterThanConstraint,
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,26 @@ import {

@ValidatorConstraint({ async: true })
@Injectable()
export class MaxGreaterThanEqualConstraint
implements ValidatorConstraintInterface
{
export class LessThanEqualConstraint implements ValidatorConstraintInterface {
validate(value: string, args: ValidationArguments): boolean {
const [property] = args.constraints;
const relatedValue = args.object[property];
return value <= relatedValue;
}
}

export function MaxGreaterThanEqual(
export function LessThanEqual(
property: string,
validationOptions?: ValidationOptions
) {
return function (object: Record<string, any>, propertyName: string): void {
registerDecorator({
name: 'MaxGreaterThanEqual',
name: 'LessThanEqual',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [property],
validator: MaxGreaterThanEqualConstraint,
validator: LessThanEqualConstraint,
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import {

@ValidatorConstraint({ async: true })
@Injectable()
export class MaxGreaterThanConstraint implements ValidatorConstraintInterface {
export class LessThanConstraint implements ValidatorConstraintInterface {
validate(value: string, args: ValidationArguments): boolean {
const [property] = args.constraints;
const relatedValue = args.object[property];
return value < relatedValue;
}
}

export function MaxGreaterThan(
export function LessThan(
property: string,
validationOptions?: ValidationOptions
) {
return function (object: Record<string, any>, propertyName: string): void {
registerDecorator({
name: 'MaxGreaterThan',
name: 'LessThan',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [property],
validator: MaxGreaterThanConstraint,
validator: LessThanConstraint,
});
};
}
14 changes: 12 additions & 2 deletions src/languages/en/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@
"isNumber": "{property} should be a number {value}.",
"isMongoId": "{property} should reference with mongo object id.",
"isBoolean": "{property} should be a boolean",
"IsStartWith": "{property} should start with {value}",
"isEnum": "{property} don't match with enum",
"isObject": "{property} should be a object",
"isArray": "{property} should be a array",
"arrayNotEmpty": "{property} array is not empty",
"minDate": "{property} has less date than the minimum allowed.",
"maxDate": "{property} has more elements than the maximum allowed.",
"isDate": "{property} should be a date",
"minDateGreaterThan": "{property} has less date than the {value}",

"isPasswordStrong": "{property} must have strong pattern",
"isPasswordMedium": "{property} must have medium pattern",
"isPasswordWeak": "{property} must have weak pattern",
"isStartWith": "{property} should start with {value}",
"safeString": "{property} should safe string, only contain A-Z, a-z, 0-9 and symbol allowed is '_-'",
"isOnlyDigits": "{property} should be a digits",
"mobileNumberAllowed": "{property} should be a mobile number that allowed",
"maxBinaryFile": "{property} size is more than max. {property} should less than {value}",
"dateGreaterThanEqualToday": "{property} must greater than equal today",
"dateLessThanEqualToday": "{property} must less than equal today",
"LessThan": "{property} has less than {value}",
"lessThanEqual": "{property} must less than equal {value}",
"greaterThan": "{property} must greater than {value}",
"greaterThanEqual": "{property} must greater than equal {value}",
"error": {
"userAgentInvalid": "Request user agent not acceptable",
"userAgentOsInvalid": "Request user agent OS not acceptable",
Expand Down

0 comments on commit c25f56c

Please sign in to comment.