@@ -6,21 +6,21 @@ import {
66 RequestTimeoutException ,
77 UnprocessableEntityException ,
88} from '@nestjs/common' ;
9- import { ModuleRef } from '@nestjs/core' ;
10- import { Document , ModifyResult , Query , Types } from 'mongoose' ;
11- import { AbstractQueueProcessor } from '~/_common/abstracts/abstract.queue.processor' ;
12- import { IdentityState } from '~/management/identities/_enums/states.enum' ;
13- import { Identities } from '~/management/identities/_schemas/identities.schema' ;
14- import { IdentitiesCrudService } from '~/management/identities/identities-crud.service' ;
15- import { JobState } from '../jobs/_enums/state.enum' ;
16- import { Jobs } from '../jobs/_schemas/jobs.schema' ;
17- import { JobsService } from '../jobs/jobs.service' ;
18- import { Tasks } from '../tasks/_schemas/tasks.schema' ;
19- import { TasksService } from '../tasks/tasks.service' ;
20- import { ActionType } from './_enum/action-type.enum' ;
21- import { ExecuteJobOptions } from './_interfaces/execute-job-options.interface' ;
22- import { WorkerResultInterface } from '~/core/backends/_interfaces/worker-result.interface' ;
23- import { DataStatusEnum } from '~/management/identities/_enums/data-status' ;
9+ import { ModuleRef } from '@nestjs/core' ;
10+ import { Document , ModifyResult , Query , Types } from 'mongoose' ;
11+ import { AbstractQueueProcessor } from '~/_common/abstracts/abstract.queue.processor' ;
12+ import { IdentityState } from '~/management/identities/_enums/states.enum' ;
13+ import { Identities } from '~/management/identities/_schemas/identities.schema' ;
14+ import { IdentitiesCrudService } from '~/management/identities/identities-crud.service' ;
15+ import { JobState } from '../jobs/_enums/state.enum' ;
16+ import { Jobs } from '../jobs/_schemas/jobs.schema' ;
17+ import { JobsService } from '../jobs/jobs.service' ;
18+ import { Tasks } from '../tasks/_schemas/tasks.schema' ;
19+ import { TasksService } from '../tasks/tasks.service' ;
20+ import { ActionType } from './_enum/action-type.enum' ;
21+ import { ExecuteJobOptions } from './_interfaces/execute-job-options.interface' ;
22+ import { WorkerResultInterface } from '~/core/backends/_interfaces/worker-result.interface' ;
23+ import { DataStatusEnum } from '~/management/identities/_enums/data-status' ;
2424
2525const DEFAULT_SYNC_TIMEOUT = 30_000 ;
2626
@@ -248,6 +248,45 @@ export class BackendsService extends AbstractQueueProcessor {
248248 return result ;
249249 }
250250
251+ public async lifecycleChangedIdentities ( payload : string [ ] , options ?: ExecuteJobOptions ) : Promise < any > {
252+ const identities : {
253+ action : ActionType ;
254+ identity : Identities ;
255+ } [ ] = [ ] ;
256+
257+ if ( ! payload . length ) throw new BadRequestException ( 'No identities to sync' ) ;
258+
259+ for ( const key of payload ) {
260+ const identity = await this . identitiesService . findById < any > ( key ) ;
261+ // cas des fusion l employeeNumber doit etre celui de l identite primaire
262+ if ( identity . primaryEmployeeNumber !== null && identity . primaryEmployeeNumber !== '' ) {
263+ identity . inetOrgPerson . employeeNumber = identity . primaryEmployeeNumber ;
264+ } else {
265+ // on prend la premiere pour envoyer une chaine et non un tableau pour la compatibilité ldap
266+ identity . inetOrgPerson . employeeNumber = identity . inetOrgPerson . employeeNumber [ 0 ] ;
267+ }
268+ identities . push ( {
269+ action : ActionType . IDENTITY_LIFECYCLE_CHANGED ,
270+ identity,
271+ } ) ;
272+ }
273+
274+ const task : Tasks = await this . tasksService . create < Tasks > ( {
275+ jobs : identities . map ( ( identity ) => identity . identity . _id ) ,
276+ } ) ;
277+
278+ const result = { } ;
279+ for ( const identity of identities ) {
280+ const [ executedJob ] = await this . executeJob ( identity . action , identity . identity . _id , identity . identity , {
281+ ...options ,
282+ updateStatus : true ,
283+ task : task . _id ,
284+ } ) ;
285+ result [ identity . identity . _id ] = executedJob ;
286+ }
287+ return result ;
288+ }
289+
251290 public async deleteIdentities ( payload : string [ ] , options ?: ExecuteJobOptions ) : Promise < any > {
252291 const identities : {
253292 action : ActionType ;
@@ -295,7 +334,7 @@ export class BackendsService extends AbstractQueueProcessor {
295334 task : task . _id ,
296335 } ) ;
297336 result [ identity . identity . _id ] = executedJob ;
298- console . log ( res ) ;
337+ // console.log(res);
299338 }
300339 return result ;
301340 }
@@ -397,6 +436,7 @@ export class BackendsService extends AbstractQueueProcessor {
397436 }
398437 return result ;
399438 }
439+
400440 public async activationIdentity ( payload : string , status : boolean , options ?: ExecuteJobOptions ) {
401441 let result = null ;
402442 if ( status === true ) {
@@ -434,10 +474,10 @@ export class BackendsService extends AbstractQueueProcessor {
434474 }
435475 //anonymisation payload sur reset et changement de mdp
436476 if ( actionType === ActionType . IDENTITY_PASSWORD_RESET || actionType === ActionType . IDENTITY_PASSWORD_CHANGE ) {
437- payload [ 'newPassword' ] = '**********' ;
477+ payload [ 'newPassword' ] = '**********' ;
438478 }
439479 if ( actionType === ActionType . IDENTITY_PASSWORD_CHANGE ) {
440- payload [ 'oldPassword' ] = '**********' ;
480+ payload [ 'oldPassword' ] = '**********' ;
441481 }
442482 let jobStore : Document < Jobs > = null ;
443483 if ( ! options ?. disableLogs ) {
0 commit comments