@@ -15,23 +15,54 @@ export class IdentitiesCrudService extends AbstractIdentitiesService {
1515 options ?: SaveOptions ,
1616 ) : Promise < Document < T , any , T > > {
1717 data = this . transformNullsToString ( data ) ;
18+
19+ const logPrefix = `Validation [${ data . inetOrgPerson . cn } ]:` ;
20+ try {
21+ this . logger . log ( `${ logPrefix } Starting additionalFields transformation.` ) ;
22+ if ( data . hasOwnProperty ( 'metadata' ) ) {
23+ //suppresion de la clé metadata
24+ delete ( data . metadata ) ;
25+ }
26+
27+ await this . _validation . transform ( data . additionalFields ) ;
28+
29+ let validationsAdFields = await this . _validation . validate ( data . additionalFields ) ;
30+
31+ this . logger . log ( `${ logPrefix } AdditionalFields validation successful.` ) ;
32+ this . logger . log ( `Validations Additional fields: ${ validationsAdFields } ` ) ;
33+ } catch ( error ) {
34+ console . log ( error ) ;
35+ if ( error instanceof ValidationConfigException ) {
36+ this . logger . error ( `${ logPrefix } Validation config error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
37+ throw new ValidationConfigException ( error . getPayload ( ) ) ;
38+ }
39+ if ( error instanceof ValidationSchemaException ) {
40+ this . logger . warn ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
41+ data . additionalFields . validations = error . getValidations ( ) ;
42+ throw new ValidationSchemaException ( error . getPayload ( ) ) ;
43+ } else {
44+ this . logger . error ( `${ logPrefix } Unhandled error: ${ error . message } ` ) ;
45+ throw error ; // Rethrow the original error if it's not one of the handled types.
46+ }
47+ }
48+
1849 await this . checkInetOrgPersonJpegPhoto ( data ) ;
1950 if ( await this . checkMailAndUid ( data ) === false ) {
2051 this . logger . error ( 'Uid ou mail déjà présent dans une autre identité' ) ;
2152 throw new HttpException ( "Uid ou mail déjà présent dans une autre identité" , 400 ) ;
2253 }
23- const logPrefix = `Validation [${ data . inetOrgPerson . cn } ]:` ;
2454 this . logger . log ( `${ logPrefix } Starting inetOrgPerson validation.` ) ;
2555 const check = {
26- objectClasses : [ 'inetorgperson ' ] ,
27- attributes : { 'inetorgperson ' : data . inetOrgPerson }
56+ objectClasses : [ 'inetOrgPerson ' ] ,
57+ attributes : { 'inetOrgPerson ' : data . inetOrgPerson }
2858 }
2959 //pour la validation le employeeNumber doit exister on en met un avec une valeur par defaut
30- check . attributes . inetorgperson . employeeNumber = [ "1" ] ;
60+ check . attributes . inetOrgPerson . employeeNumber = [ "1" ] ;
3161 let validations = await this . _validation . validate ( check ) ;
3262 const created : Document < T , any , T > = await super . create ( data , options ) ;
3363 return created ;
3464 }
65+
3566 public async update < T extends AbstractSchema | Document > (
3667 _id : Types . ObjectId | any ,
3768 update : UpdateQuery < T > ,
@@ -53,8 +84,8 @@ export class IdentitiesCrudService extends AbstractIdentitiesService {
5384
5485 this . logger . log ( `${ logPrefix } Starting inetOrgPerson validation.` ) ;
5586 const check = {
56- objectClasses : [ 'inetorgperson ' ] ,
57- attributes : { 'inetorgperson ' : update . inetOrgPerson }
87+ objectClasses : [ 'inetOrgPerson ' ] ,
88+ attributes : { 'inetOrgPerson ' : update . inetOrgPerson }
5889 }
5990 let validationsInetOrg = await this . _validation . validate ( check ) ;
6091 let validationsAdFields = await this . _validation . validate ( update . additionalFields ) ;
0 commit comments