@@ -5,6 +5,7 @@ import { ValidationConfigException, ValidationSchemaException } from '~/_common/
55import { IdentityState } from '~/management/identities/_enums/states.enum' ;
66import { Identities } from '~/management/identities/_schemas/identities.schema' ;
77import { HttpException } from '@nestjs/common' ;
8+ import { omit } from 'radash' ;
89
910export class IdentitiesCrudService extends AbstractIdentitiesService {
1011 public async create < T extends AbstractSchema | Document > (
@@ -14,9 +15,9 @@ export class IdentitiesCrudService extends AbstractIdentitiesService {
1415 data = this . transformNullsToString ( data ) ;
1516 await this . checkInetOrgPersonJpegPhoto ( data ) ;
1617 //recherche si email oy uid deja present
17- const f :any = { $or : [ { 'inetOrgPerson.uid' : data . inetOrgPerson . uid } , { 'inetOrgPerson.mail' : data . inetOrgPerson . mail } ] } ;
18+ const f : any = { $or : [ { 'inetOrgPerson.uid' : data . inetOrgPerson . uid } , { 'inetOrgPerson.mail' : data . inetOrgPerson . mail } ] } ;
1819 let dataDup = await this . _model . countDocuments ( f ) . exec ( )
19- if ( dataDup > 0 ) {
20+ if ( dataDup > 0 ) {
2021 this . logger . error ( 'Identité existante' ) ;
2122 throw new HttpException ( "Uid ou mail déjà présent dans une autre identité" , 400 ) ;
2223 }
@@ -53,16 +54,22 @@ export class IdentitiesCrudService extends AbstractIdentitiesService {
5354 }
5455
5556 // if (update.state === IdentityState.TO_COMPLETE) {
56- update = { ...update , state : IdentityState . TO_VALIDATE } ;
57+ update = {
58+ ...omit ( update , [ 'inetOrgPerson' ] ) ,
59+ inetOrgPerson : omit ( update . inetOrgPerson , [ 'employeeNumber' , 'employeeType' ] ) ,
60+ state : IdentityState . TO_VALIDATE ,
61+ } ;
5762
5863 await this . checkInetOrgPersonJpegPhoto ( update ) ;
5964
65+ console . log ( 'update' , update , _id , options )
66+
6067 // }
6168 // if (update.state === IdentityState.SYNCED) {
6269 // update = { ...update, state: IdentityState.TO_VALIDATE };
6370 // }
6471 //update.state = IdentityState.TO_VALIDATE;
65- const updated = await super . update ( _id , update , options ) ;
72+ const updated = await super . update ( _id , { $set : update } , options ) ;
6673 //TODO: add backends service logic here (TO_SYNC)
6774 return await this . generateFingerprint ( updated as unknown as Identities ) ;
6875 }
0 commit comments