Skip to content

Commit d0f468d

Browse files
committed
refactor: streamline identity lifecycle updates in LifecycleHooksService
- Enhanced the LifecycleHooksService to conditionally set the target state for identity updates based on attribute mutations, improving clarity and efficiency in lifecycle event handling. - Consolidated logging for identity updates to provide clearer context on lifecycle transitions.
1 parent e4379a5 commit d0f468d

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

apps/api/src/management/lifecycle/lifecycle-hooks.service.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ export class LifecycleHooksService extends AbstractLifecycleService {
354354
date: new Date(),
355355
});
356356

357+
if (hasMutation) {
358+
await this.backendsService.lifecycleChangedIdentities(
359+
[{ id: updated._id.toString(), before: identity, after: updated }],
360+
{ targetState: IdentityState.TO_SYNC },
361+
);
362+
}
363+
357364
this.logger.log(
358365
`Identity <${identity._id}> updated to lifecycle <${idRule.target}> by trigger from source <${idRule.sources}>`,
359366
);
@@ -562,17 +569,16 @@ export class LifecycleHooksService extends AbstractLifecycleService {
562569
date: new Date(),
563570
});
564571

565-
if (hasMutation) {
566-
this.logger.log(
567-
`Identity <${res._id}> updated to lifecycle <${lcs.target}> with attribute mutation, set to TO_SYNC`,
568-
);
569-
} else {
570-
const identities = res._id ? [{ id: res._id.toString(), before: after, after: res }] : [];
571-
await this.backendsService.lifecycleChangedIdentities(identities);
572-
this.logger.log(
573-
`Identity <${res._id}> updated to lifecycle <${lcs.target}> based on rules from source <${after.lifecycle}>`,
574-
);
575-
}
572+
const identities = res._id ? [{ id: res._id.toString(), before: after, after: res }] : [];
573+
await this.backendsService.lifecycleChangedIdentities(identities, {
574+
...(hasMutation ? { targetState: IdentityState.TO_SYNC } : {}),
575+
});
576+
577+
this.logger.log(
578+
hasMutation
579+
? `Identity <${res._id}> updated to lifecycle <${lcs.target}> with attribute mutation, lifecycle event sent and set to TO_SYNC`
580+
: `Identity <${res._id}> updated to lifecycle <${lcs.target}> based on rules from source <${after.lifecycle}>`,
581+
);
576582
return;
577583
}
578584
}

0 commit comments

Comments
 (0)