@@ -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,28 @@ 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+ throw new ValidationSchemaException ( error . getPayload ( ) ) ;
90+ } else {
91+ this . logger . error ( `${ logPrefix } Unhandled error: ${ error . message } ` ) ;
92+ throw error ; // Rethrow the original error if it's not one of the handled types.
93+ }
94+ }
95+ //update.state = IdentityState.TO_VALIDATE;
7496 const updated = await super . update ( _id , update , options ) ;
7597 //TODO: add backends service logic here (TO_SYNC)
7698 return updated ;
@@ -89,23 +111,23 @@ export class IdentitiesService extends AbstractServiceSchema {
89111
90112 private handleValidationError ( error : Error | HttpException , identity : Identities , logPrefix : string ) {
91113 if ( error instanceof ValidationConfigException ) {
92- Logger . error ( `${ logPrefix } Validation config error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
114+ this . logger . error ( `${ logPrefix } Validation config error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
93115 throw new ValidationConfigException ( error . getPayload ( ) ) ;
94116 }
95117
96118 if ( error instanceof ValidationSchemaException ) {
97- Logger . warn ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
119+ this . logger . warn ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
98120 identity . additionalFields . validations = error . getValidations ( ) ;
99121 if ( identity . state === IdentityState . TO_CREATE ) {
100- Logger . warn ( `${ logPrefix } State set to TO_COMPLETE.` ) ;
122+ this . logger . warn ( `${ logPrefix } State set to TO_COMPLETE.` ) ;
101123 identity . state = IdentityState . TO_COMPLETE ;
102124 return identity ;
103125 } else {
104- Logger . error ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
126+ this . logger . error ( `${ logPrefix } Validation schema error. ${ JSON . stringify ( error . getValidations ( ) ) } ` ) ;
105127 throw new ValidationSchemaException ( error . getPayload ( ) ) ;
106128 }
107129 } else {
108- Logger . error ( `${ logPrefix } Unhandled error: ${ error . message } ` ) ;
130+ this . logger . error ( `${ logPrefix } Unhandled error: ${ error . message } ` ) ;
109131 throw error ; // Rethrow the original error if it's not one of the handled types.
110132 }
111133 }
0 commit comments