@@ -5,13 +5,12 @@ import {ConfigObjectSchemaDTO} from './_dto/config.dto';
55import { diff } from 'radash' ;
66import { AdditionalFieldsPart } from '../_schemas/_parts/additionalFields.part.schema' ;
77import Ajv from 'ajv' ;
8- import { buildYup } from 'schema-to-yup ' ;
8+ import addFormats from 'ajv-formats ' ;
99import validSchema from './_config/validSchema' ;
1010import ajvErrors from 'ajv-errors' ;
1111import { ValidationConfigException , ValidationSchemaException } from '~/_common/errors/ValidationException' ;
1212import { additionalFieldsPartDto } from '../_dto/_parts/additionalFields.dto' ;
1313
14-
1514/**
1615 * Service responsible for validating identities.
1716 */
@@ -22,7 +21,9 @@ export class IdentitiesValidationService implements OnApplicationBootstrap {
2221 private logger : Logger ;
2322
2423 public constructor ( ) {
24+ addFormats ( this . ajv ) ;
2525 ajvErrors ( this . ajv ) ;
26+ this . ajv . addFormat ( 'number' , / ^ \d * $ / ) ;
2627 this . validateSchema = this . ajv . compile ( validSchema ) ;
2728 this . logger = new Logger ( IdentitiesValidationService . name ) ;
2829 }
@@ -242,7 +243,7 @@ export class IdentitiesValidationService implements OnApplicationBootstrap {
242243 * @param attribute - The attribute value to validate.
243244 * @returns A promise that resolves with an error message if validation fails, otherwise null.
244245 */
245- public async validateAttribute ( key : string , attribute : any , data : any ) : Promise < string | null > {
246+ public async validateAttribute ( key : string , attribute : any , data : any ) : Promise < any | null > {
246247 const path = this . resolveConfigPath ( key ) ;
247248 const schema : any = parse ( readFileSync ( path , 'utf8' ) ) ;
248249
@@ -269,17 +270,15 @@ export class IdentitiesValidationService implements OnApplicationBootstrap {
269270 }
270271
271272 this . logger . debug ( `Additionalfields object validation: ${ JSON . stringify ( data [ key ] ) } ` ) ;
272-
273- const yupSchema = buildYup ( schema , { noSortEdges : true } ) ;
274- try {
275- await yupSchema . validate ( attribute , { strict : true , abortEarly : false } ) ;
276- return null ;
277- } catch ( error ) {
278- return error . inner . reduce ( ( acc , err ) => {
279- acc [ err . path ] = err . message ;
280- return acc ;
281- } , { } ) ;
273+ const ok = await this . ajv . validate ( schema , data [ key ] ) ;
274+ if ( ok === false ) {
275+ const retErrors = { } ;
276+ for ( const err of this . ajv . errors ) {
277+ retErrors [ err [ 'instancePath' ] . substring ( 1 ) ] = err [ 'instancePath' ] . substring ( 1 ) + ' ' + err [ 'message' ]
278+ }
279+ return ( retErrors )
282280 }
281+ return null
283282 }
284283
285284 public async findAll ( ) : Promise < any > {
0 commit comments