Skip to content

Commit ce9eb5f

Browse files
committed
fusion
1 parent 18e4a24 commit ce9eb5f

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/core/backends/backends.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export class BackendsService extends AbstractQueueProcessor {
136136
await this.identitiesService.model.findByIdAndUpdate(completedJob?.concernedTo?.id, {
137137
$set: {
138138
state: iState,
139+
lastBackendSync: jState === JobState.COMPLETED ? new Date() : null,
139140
},
140141
});
141142
if (jState === JobState.COMPLETED) {
@@ -196,14 +197,18 @@ export class BackendsService extends AbstractQueueProcessor {
196197
if (!payload.length) throw new BadRequestException('No identities to sync');
197198

198199
for (const key of payload) {
199-
const identity = await this.identitiesService.findById<Identities>(key);
200+
const identity = await this.identitiesService.findById<any>(key);
200201
if (identity.state !== IdentityState.TO_SYNC) {
201202
throw new BadRequestException({
202203
status: HttpStatus.BAD_REQUEST,
203204
message: `Identity ${key} is not in state TO_SYNC`,
204205
identity,
205206
});
206207
}
208+
// cas des fusion l employeeNumber doit etre celui de l identite primaire
209+
if (identity.primaryEmployeeNumber !== null) {
210+
identity.inetOrgPerson.employeeNumber = identity.primaryEmployeeNumber;
211+
}
207212
identities.push({
208213
action: ActionType.IDENTITY_UPDATE,
209214
identity,
@@ -236,7 +241,7 @@ export class BackendsService extends AbstractQueueProcessor {
236241

237242
for (const key of payload) {
238243
const identity = await this.identitiesService.findById<Identities>(key);
239-
if (!identity.lastSync) {
244+
if (!identity.lastBackendSync) {
240245
throw new BadRequestException({
241246
status: HttpStatus.BAD_REQUEST,
242247
message: `Identity ${key} is not in state TO_DELETE`,

src/management/identities/_schemas/identities.schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export class Identities extends AbstractSchema {
3333
@Prop({ type: Date })
3434
public lastSync?: Date;
3535

36+
@Prop({ type: Date, default: null })
37+
public lastBackendSync: Date;
38+
3639
@Prop({ type: Number, enum: InitStatesEnum, default: InitStatesEnum.NOSENT })
3740
public initState: InitStatesEnum;
3841

@@ -45,7 +48,7 @@ export class Identities extends AbstractSchema {
4548
public customFields?: { [key: string]: MixedValue };
4649

4750
//pour les identités fusionnées ont met les deux identités sources
48-
@Prop({ type: Types.ObjectId, required: false })
51+
@Prop({ type: Types.ObjectId, required: false, default: null })
4952
public srcFusionId: Types.ObjectId;
5053

5154
//pour les identités qui on servit à une fusion on met la destination (la nouvelle identité fusionnée)

src/management/identities/identities.service.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)