feat: add update profile service
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
ValidatorConstraint,
|
||||
ValidatorConstraintInterface,
|
||||
} from 'class-validator';
|
||||
import { I18nContext } from 'nestjs-i18n';
|
||||
|
||||
@ValidatorConstraint({ name: 'MatchFields', async: false })
|
||||
export class MatchFieldsConstraint implements ValidatorConstraintInterface {
|
||||
@@ -18,6 +19,14 @@ export class MatchFieldsConstraint implements ValidatorConstraintInterface {
|
||||
defaultMessage(args: ValidationArguments): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const [property] = args.constraints;
|
||||
return `${args.property} must match ${property}`;
|
||||
const i18n = I18nContext.current();
|
||||
|
||||
const field1 = i18n?.t(`users.fields.${args.property}`) ?? args.property;
|
||||
const field2 = i18n?.t(`users.fields.${property}`) ?? (property as string);
|
||||
|
||||
return (
|
||||
i18n?.t('validation.fieldsMustMatch', { args: { field1, field2 } }) ??
|
||||
`${args.property} must match ${property}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user