@@ -34,10 +34,10 @@ export class IdentitiesService extends AbstractServiceSchema {
3434 const logPrefix = `Validation [${ data . inetOrgPerson . cn } ]:` ;
3535 data . additionalFields . validations = { } ;
3636 try {
37- Logger . log ( `${ logPrefix } Starting additionalFields validation.` ) ;
37+ this . logger . log ( `${ logPrefix } Starting additionalFields validation.` ) ;
3838 const validations = await this . _validation . validate ( data . additionalFields ) ;
39- Logger . log ( `${ logPrefix } AdditionalFields validation successful.` ) ;
40- Logger . log ( `Validations : ${ validations } ` ) ;
39+ this . logger . log ( `${ logPrefix } AdditionalFields validation successful.` ) ;
40+ this . logger . log ( `Validations : ${ validations } ` ) ;
4141 data . state = IdentityState . TO_VALIDATE ;
4242 } catch ( error ) {
4343 data = this . handleValidationError ( error , data , logPrefix ) ;
@@ -46,7 +46,7 @@ export class IdentitiesService extends AbstractServiceSchema {
4646 //TODO: ameliorer la logique d'upsert
4747 const identity = await this . _model . findOne ( { 'inetOrgPerson.uid' : data . inetOrgPerson . uid } ) ;
4848 if ( identity ) {
49- Logger . log ( `${ logPrefix } Identity already exists. Updating.` ) ;
49+ this . logger . log ( `${ logPrefix } Identity already exists. Updating.` ) ;
5050 data . additionalFields . objectClasses = [
5151 ...new Set ( [ ...identity . additionalFields . objectClasses , ...data . additionalFields . objectClasses ] ) ,
5252 ] ;
@@ -71,6 +71,29 @@ export class IdentitiesService extends AbstractServiceSchema {
7171 options ?: QueryOptions < T > & { rawResult : true } ,
7272 ) : Promise < ModifyResult < Query < T , T , any , T > > > {
7373 // noinspection UnnecessaryLocalVariableJS
74+ //TODO : add validation logic here
75+ const logPrefix = `Validation [${ update . inetOrgPerson . cn } ]:` ;
76+ try {
77+ this . logger . log ( `${ logPrefix } Starting additionalFields validation.` ) ;
78+ const validations = await this . _validation . validate ( update . additionalFields ) ;
79+ this . logger . log ( `${ logPrefix } AdditionalFields validation successful.` ) ;
80+ this . logger . log ( `Validations : ${ validations } ` ) ;
81+ } catch ( error ) {
82+ if ( error instanceof ValidationConfigException ) {
83+ this . logger . error ( `${ logPrefix } Validation config error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
84+ throw new ValidationConfigException ( error . getPayload ( ) ) ;
85+ }
86+ if ( error instanceof ValidationSchemaException ) {
87+ this . logger . warn ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
88+ update . additionalFields . validations = error . getValidations ( ) ;
89+ this . logger . error ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
90+ throw new ValidationSchemaException ( error . getPayload ( ) ) ;
91+ } else {
92+ this . logger . error ( `${ logPrefix } Unhandled error: ${ error . message } ` ) ;
93+ throw error ; // Rethrow the original error if it's not one of the handled types.
94+ }
95+ }
96+ console . log ( 'update' , update ) ;
7497 const updated = await super . update ( _id , update , options ) ;
7598 //TODO: add backends service logic here (TO_SYNC)
7699 return updated ;
@@ -89,23 +112,23 @@ export class IdentitiesService extends AbstractServiceSchema {
89112
90113 private handleValidationError ( error : Error | HttpException , identity : Identities , logPrefix : string ) {
91114 if ( error instanceof ValidationConfigException ) {
92- Logger . error ( `${ logPrefix } Validation config error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
115+ this . logger . error ( `${ logPrefix } Validation config error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
93116 throw new ValidationConfigException ( error . getPayload ( ) ) ;
94117 }
95118
96119 if ( error instanceof ValidationSchemaException ) {
97- Logger . warn ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
120+ this . logger . warn ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
98121 identity . additionalFields . validations = error . getValidations ( ) ;
99122 if ( identity . state === IdentityState . TO_CREATE ) {
100- Logger . warn ( `${ logPrefix } State set to TO_COMPLETE.` ) ;
123+ this . logger . warn ( `${ logPrefix } State set to TO_COMPLETE.` ) ;
101124 identity . state = IdentityState . TO_COMPLETE ;
102125 return identity ;
103126 } else {
104- Logger . error ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
127+ this . logger . error ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
105128 throw new ValidationSchemaException ( error . getPayload ( ) ) ;
106129 }
107130 } else {
108- Logger . error ( `${ logPrefix } Unhandled error: ${ error . message } ` ) ;
131+ this . logger . error ( `${ logPrefix } Unhandled error: ${ error . message } ` ) ;
109132 throw error ; // Rethrow the original error if it's not one of the handled types.
110133 }
111134 }
0 commit comments