Skip to content

Commit e8b541c

Browse files
committed
corrections upsert
1 parent f45b32d commit e8b541c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/management/identities/abstract-identities.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export abstract class AbstractIdentitiesService extends AbstractServiceSchema {
234234
let dataDup = 0;
235235
if (data.inetOrgPerson.hasOwnProperty('mail') && data.inetOrgPerson.mail !== '') {
236236
if (identity){
237-
const f: any = { '_id': { $ne: identity._id }, 'inetOrgPerson.mail': identity.inetOrgPerson.mail };
237+
const f: any = { '_id': { $ne: identity._id },'state':{$ne:IdentityState.DONT_SYNC},'deletedFlag':{$ne:true}, 'inetOrgPerson.mail': identity.inetOrgPerson.mail };
238238
dataDup = await this._model.countDocuments(f).exec()
239239
}else{
240240
const f: any = { 'inetOrgPerson.mail': data.inetOrgPerson.mail };
@@ -252,7 +252,7 @@ export abstract class AbstractIdentitiesService extends AbstractServiceSchema {
252252
protected async checkUid(identity,data): Promise<boolean> {
253253
let dataDup = 0;
254254
if (identity){
255-
const f: any = { '_id': { $ne: identity._id }, 'inetOrgPerson.uid': identity.inetOrgPerson.uid };
255+
const f: any = { '_id': { $ne: identity._id } ,'state':{$ne:IdentityState.DONT_SYNC},'deletedFlag':{$ne:true},'inetOrgPerson.uid': identity.inetOrgPerson.uid };
256256
dataDup = await this._model.countDocuments(f).exec()
257257
}else{
258258
const f: any = { 'inetOrgPerson.uid': data.inetOrgPerson.uid };

src/management/identities/identities-doublon.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ export class IdentitiesDoublonService extends AbstractIdentitiesService {
142142
identity1.additionalFields.objectClasses.includes('supannPerson') &&
143143
identity2.additionalFields.objectClasses.includes('supannPerson')
144144
) {
145-
if (identity2.additionalFields.attributes.supannPerson.includes('supannTypeEntiteAffectation') ) {
145+
if (identity2.additionalFields.attributes.supannPerson.supannTypeEntiteAffectation ) {
146146
identity2.additionalFields.attributes.supannPerson.supannTypeEntiteAffectation.forEach((depN) => {
147147
(identity1.additionalFields.attributes.supannPerson as any).supannTypeEntiteAffectation.push(depN);
148148
});
149149
}
150150
// supannRefId
151-
if (identity2.additionalFields.attributes.supannPerson.includes('supannRefId') ){
151+
if (identity2.additionalFields.attributes.supannPerson.supannRefId ){
152152
identity2.additionalFields.attributes.supannPerson.supannRefId.forEach((depN) => {
153153
(identity1.additionalFields.attributes.supannPerson as any).supannRefId.push(depN);
154154
});

src/management/identities/identities-upsert.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export class IdentitiesUpsertService extends AbstractIdentitiesService {
2424
this.logger.log(`Upserting identity with filters ${JSON.stringify(filters)}`);
2525
const crushedUpdate = toPlainAndCrush(omit(data || {}, ['$setOnInsert']));
2626
const crushedSetOnInsert = toPlainAndCrush(data.$setOnInsert || {});
27+
let employeeNumber=""
28+
if (data?.$setOnInsert.inetOrgPerson.employeeNumber){
29+
employeeNumber=data.$setOnInsert.inetOrgPerson.employeeNumber[0];
30+
}else{
31+
employeeNumber=data.inetOrgPerson.employeeNumber[0];
32+
}
33+
2734
data = construct({
2835
...crushedSetOnInsert,
2936
...toPlainAndCrush(identity?.toJSON() || {}, {
@@ -42,8 +49,8 @@ export class IdentitiesUpsertService extends AbstractIdentitiesService {
4249
);
4350
}
4451
//controle si l identité est fusionnée si c est la bonne à mettre à jour puisqu elle a 2 employeeNumber
45-
if (identity !== null && identity?.srcFusionId) {
46-
if (identity.primaryEmployeeNumber !== data?.inetOrgPerson?.employeeNumber[0]) {
52+
if (identity !== null){
53+
if (identity.primaryEmployeeNumber !== null && identity.primaryEmployeeNumber !== employeeNumber) {
4754
throw new HttpException('Secondary identity', HttpStatus.SEE_OTHER);
4855
}
4956
}

0 commit comments

Comments
 (0)