@@ -51,10 +51,10 @@ export class IdentitiesService extends AbstractServiceSchema {
5151 data ?: IdentitiesUpsertDto ,
5252 options ?: QueryOptions < T > ,
5353 ) : Promise < [ HttpStatus . OK | HttpStatus . CREATED , ModifyResult < Query < T , T , any , T > > ] > {
54+
5455 data = this . transformNullsToString ( data ) ;
55- const identity = await this . model . findOne ( filters ) . exec ( ) ;
56+ const identity = await this . model . findOne < Identities > ( filters ) . exec ( ) ;
5657 this . logger . log ( `Upserting identity with filters ${ JSON . stringify ( filters ) } ` ) ;
57-
5858 const crushedUpdate = toPlainAndCrush ( omit ( data || { } , [ '$setOnInsert' ] ) ) ;
5959 const crushedSetOnInsert = toPlainAndCrush ( data . $setOnInsert || { } ) ;
6060 data = construct ( {
@@ -76,6 +76,15 @@ export class IdentitiesService extends AbstractServiceSchema {
7676 'inetOrgPerson.employeeNumber and inetOrgPerson.employeeType are required for create identity.' ,
7777 ) ;
7878 }
79+ if ( data . inetOrgPerson ?. employeeNumber . indexOf ( '174981' ) >= 0 || data . inetOrgPerson ?. employeeNumber . indexOf ( '162982' ) >= 0 ) {
80+ console . log ( 'test' ) ;
81+ }
82+ //controle si l identité est fusionnée si c est la bonne à mettre à jour puisqu elle a 2 employeeNumber
83+ if ( identity !== null && identity ?. srcFusionId !== null ) {
84+ if ( identity . primaryEmployeeNumber !== data ?. inetOrgPerson ?. employeeNumber [ 0 ] ) {
85+ throw new HttpException ( 'Secondary identity' , HttpStatus . SEE_OTHER ) ;
86+ }
87+ }
7988
8089 await this . checkInetOrgPersonJpegPhoto ( data ) ;
8190
@@ -487,11 +496,16 @@ export class IdentitiesService extends AbstractServiceSchema {
487496 identity1 . state = IdentityState . TO_VALIDATE ;
488497 identity1 . srcFusionId = identity2 . _id ;
489498 identity2 . destFusionId = identity1 . _id ;
499+ identity2 . inetOrgPerson . employeeNumber [ 0 ] = 'F' + identity2 . inetOrgPerson . employeeNumber [ 0 ] ;
500+ //delete identity2 si elle a deja été synchro ?
501+ if ( identity2 . lastBackendSync !== null ) {
502+ await this . backends . deleteIdentities ( [ identity2 . _id . toString ( ) ] ) ;
503+ }
490504 identity2 . state = IdentityState . DONT_SYNC ;
505+ // modification identité2
506+ await super . update ( identity2 . _id , identity2 ) ;
491507 // modification identité1
492- super . update ( identity1 . _id , identity1 ) ;
493- // modification identité1
494- super . update ( identity2 . _id , identity2 ) ;
508+ await super . update ( identity1 . _id , identity1 ) ;
495509 return identity1 . _id ;
496510 }
497511}
0 commit comments