@@ -21,6 +21,7 @@ import { ActionType } from './_enum/action-type.enum';
2121import { ExecuteJobOptions } from './_interfaces/execute-job-options.interface' ;
2222import { BackendResultInterface } from "~/core/backends/_interfaces/backend-result.interface" ;
2323import { WorkerResultInterface } from "~/core/backends/_interfaces/worker-result.interface" ;
24+ import { DataStatusEnum } from "~/management/identities/_enums/data-status" ;
2425
2526const DEFAULT_SYNC_TIMEOUT = 30_000 ;
2627
@@ -265,6 +266,93 @@ export class BackendsService extends AbstractQueueProcessor {
265266 updateStatus : true ,
266267 switchToProcessing : false ,
267268 targetState : IdentityState . DONT_SYNC ,
269+ dataState : DataStatusEnum . DELETED ,
270+ task : task . _id ,
271+ } ) ;
272+ result [ identity . identity . _id ] = executedJob ;
273+ console . log ( res ) ;
274+ }
275+ return result ;
276+ }
277+
278+ public async disableIdentities ( payload : string [ ] , options ?: ExecuteJobOptions ) : Promise < any > {
279+ const identities : {
280+ action : ActionType ;
281+ identity : Identities ;
282+ } [ ] = [ ] ;
283+
284+ if ( ! payload . length ) throw new BadRequestException ( 'No identities to disable' ) ;
285+
286+ for ( const key of payload ) {
287+ const identity = await this . identitiesService . findById < Identities > ( key ) ;
288+ if ( ! identity . lastBackendSync ) {
289+ throw new BadRequestException ( {
290+ status : HttpStatus . BAD_REQUEST ,
291+ message : `Identity ${ key } is not in state TO_DELETE` ,
292+ identity,
293+ } ) ;
294+ }
295+ identities . push ( {
296+ action : ActionType . IDENTITY_ENABLE ,
297+ identity,
298+ } ) ;
299+ }
300+
301+ const task : Tasks = await this . tasksService . create < Tasks > ( {
302+ jobs : identities . map ( ( identity ) => identity . identity . _id ) ,
303+ } ) ;
304+
305+ const result = { } ;
306+ for ( const identity of identities ) {
307+ const [ executedJob , res ] = await this . executeJob ( identity . action , identity . identity . _id , identity . identity , {
308+ ...options ,
309+ updateStatus : true ,
310+ switchToProcessing : false ,
311+ targetState : IdentityState . SYNCED ,
312+ dataState : DataStatusEnum . INACTIVE ,
313+ task : task . _id ,
314+ } ) ;
315+ result [ identity . identity . _id ] = executedJob ;
316+ console . log ( res ) ;
317+ }
318+ return result ;
319+ }
320+
321+ public async enableIdentities ( payload : string [ ] , options ?: ExecuteJobOptions ) : Promise < any > {
322+ const identities : {
323+ action : ActionType ;
324+ identity : Identities ;
325+ } [ ] = [ ] ;
326+
327+ if ( ! payload . length ) throw new BadRequestException ( 'No identities to disable' ) ;
328+
329+ for ( const key of payload ) {
330+ const identity = await this . identitiesService . findById < Identities > ( key ) ;
331+ if ( ! identity . lastBackendSync ) {
332+ throw new BadRequestException ( {
333+ status : HttpStatus . BAD_REQUEST ,
334+ message : `Identity ${ key } is not in state TO_DELETE` ,
335+ identity,
336+ } ) ;
337+ }
338+ identities . push ( {
339+ action : ActionType . IDENTITY_ENABLE ,
340+ identity,
341+ } ) ;
342+ }
343+
344+ const task : Tasks = await this . tasksService . create < Tasks > ( {
345+ jobs : identities . map ( ( identity ) => identity . identity . _id ) ,
346+ } ) ;
347+
348+ const result = { } ;
349+ for ( const identity of identities ) {
350+ const [ executedJob , res ] = await this . executeJob ( identity . action , identity . identity . _id , identity . identity , {
351+ ...options ,
352+ updateStatus : true ,
353+ switchToProcessing : false ,
354+ targetState : IdentityState . SYNCED ,
355+ dataState : DataStatusEnum . ACTIVE ,
268356 task : task . _id ,
269357 } ) ;
270358 result [ identity . identity . _id ] = executedJob ;
0 commit comments