Skip to content

Commit 7f86ed7

Browse files
committed
implementation corbeille
1 parent 1593204 commit 7f86ed7

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

src/_common/abstracts/abstract.service.schema.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export abstract class AbstractServiceSchema extends AbstractService implements S
4747
return await this._model.countDocuments(filter, options).exec()
4848
}
4949

50+
public async trashAndCount<T extends AbstractSchema | Document>(
51+
projection?: ProjectionType<T> | null | undefined,
52+
options?: QueryOptions<T> | null | undefined,
53+
):Promise<[Array<T & Query<T, T, any, T>>, number]> {
54+
const filter={deletedFlag : true}
55+
let count = await this._model.countDocuments(filter).exec()
56+
let data = await this._model.find<T & Query<T, T, any, T>>(filter, projection, options).exec()
57+
return [data, count]
58+
}
5059
public async findAndCount<T extends AbstractSchema | Document>(
5160
filter?: FilterQuery<T>,
5261
projection?: ProjectionType<T> | null | undefined,
@@ -66,6 +75,8 @@ export abstract class AbstractServiceSchema extends AbstractService implements S
6675
if (beforeEvent?.options) options = { ...options, ...beforeEvent.options }
6776
}
6877
}
78+
const softDelete={deletedFlag : {$ne: true}}
79+
filter= {...filter,...softDelete}
6980
let count = await this._model.countDocuments(filter).exec()
7081
let data = await this._model.find<T & Query<T, T, any, T>>(filter, projection, options).exec()
7182
if (this.eventEmitter) {

src/core/backends/backends.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ export class BackendsService extends AbstractQueueProcessor {
111111
});
112112

113113
this.queueEvents.on('completed', async (payload) => {
114-
let jState = JobState.COMPLETED;
115-
let iState = IdentityState.SYNCED;
114+
116115
const result = <WorkerResultInterface>(<unknown>payload.returnvalue);
116+
117117
if (result.jobName === ActionType.DUMP_PACKAGE_CONFIG || result?.options?.disableLogs === true) {
118118
return;
119119
}
120+
let jState = JobState.COMPLETED;
121+
let iState = IdentityState.SYNCED;
120122
if (result.status !== 0) {
121123
jState = JobState.FAILED;
122124
iState = IdentityState.ON_ERROR;
@@ -135,8 +137,9 @@ export class BackendsService extends AbstractQueueProcessor {
135137

136138
await this.identitiesService.model.findByIdAndUpdate(completedJob?.concernedTo?.id, {
137139
$set: {
138-
state: iState,
140+
state: result.jobName === ActionType.IDENTITY_DELETE ? IdentityState.DONT_SYNC : IdentityState.SYNCED,
139141
lastBackendSync: jState === JobState.COMPLETED ? new Date() : null,
142+
deletedFlag: result.jobName === ActionType.IDENTITY_DELETE,
140143
},
141144
});
142145
if (jState === JobState.COMPLETED) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export class Identities extends AbstractSchema {
2525
@Prop({ type: Number, enum: DataStatusEnum, default: DataStatusEnum.ACTIVE })
2626
public dataStatus: DataStatusEnum;
2727

28+
@Prop({ type: Boolean, default: false })
29+
public deletedFlag: boolean;
30+
2831
@Prop({ type: inetOrgPersonSchema, required: true })
2932
public inetOrgPerson: inetOrgPerson;
3033

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AbstractIdentitiesService } from '~/management/identities/abstract-identities.service';
22
import { Identities } from '~/management/identities/_schemas/identities.schema';
3-
import {BadRequestException, HttpException} from '@nestjs/common';
3+
import { BadRequestException, HttpException } from '@nestjs/common';
44
import { DataStatusEnum } from '~/management/identities/_enums/data-status';
55
import { JobState } from '~/core/jobs/_enums/state.enum';
66

src/management/identities/identities-crud.controller.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { Response } from 'express';
2121
import { Document, Types } from 'mongoose';
2222
import { AbstractController } from '~/_common/abstracts/abstract.controller';
2323
import { ApiCreateDecorator } from '~/_common/decorators/api-create.decorator';
24-
import { ApiDeletedResponseDecorator } from '~/_common/decorators/api-deleted-response.decorator';
2524
import { ApiPaginatedDecorator } from '~/_common/decorators/api-paginated.decorator';
2625
import { ApiReadResponseDecorator } from '~/_common/decorators/api-read-response.decorator';
2726
import { ApiUpdateDecorator } from '~/_common/decorators/api-update.decorator';
@@ -98,6 +97,30 @@ export class IdentitiesCrudController extends AbstractController {
9897
message,
9998
});
10099
}
100+
@Get('getdeleted')
101+
@ApiPaginatedDecorator(PickProjectionHelper(IdentitiesDto, IdentitiesCrudController.projection))
102+
public async getdeleted(
103+
@Res() res: Response,
104+
@SearchFilterOptions() searchFilterOptions: FilterOptions,
105+
): Promise<
106+
Response<
107+
{
108+
statusCode: number;
109+
data?: Document<Identities, any, Identities>;
110+
total?: number;
111+
message?: string;
112+
validations?: MixedValue;
113+
},
114+
any
115+
>
116+
> {
117+
const [data, total] = await this._service.trashAndCount(IdentitiesCrudController.projection, searchFilterOptions);
118+
return res.status(HttpStatus.OK).json({
119+
statusCode: HttpStatus.OK,
120+
total,
121+
data,
122+
});
123+
}
101124

102125
@Get()
103126
@ApiPaginatedDecorator(PickProjectionHelper(IdentitiesDto, IdentitiesCrudController.projection))
@@ -224,9 +247,9 @@ export class IdentitiesCrudController extends AbstractController {
224247
});
225248
}
226249

227-
@Delete(':_id([0-9a-fA-F]{24})')
228-
@ApiParam({ name: '_id', type: String })
229-
@ApiDeletedResponseDecorator(IdentitiesDto)
250+
//@Delete(':_id([0-9a-fA-F]{24})')
251+
//@ApiParam({ name: '_id', type: String })
252+
//@ApiDeletedResponseDecorator(IdentitiesDto)
230253
public async remove(
231254
@Param('_id', ObjectIdValidationPipe) _id: Types.ObjectId,
232255
@Res() res: Response,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export class IdentitiesCrudService extends AbstractIdentitiesService {
1515
await this.checkInetOrgPersonJpegPhoto(data);
1616
const created: Document<T, any, T> = await super.create(data, options);
1717
return created;
18-
//TODO: add backends service logic here
1918
}
2019
public async update<T extends AbstractSchema | Document>(
2120
_id: Types.ObjectId | any,
@@ -91,15 +90,13 @@ export class IdentitiesCrudService extends AbstractIdentitiesService {
9190

9291
return updated as any;
9392
}
94-
93+
//Attention le front appelle backend/delete pour deleter l identite. La methode ci dessous n est pas utilisée
9594
public async delete<T extends AbstractSchema | Document>(
9695
_id: Types.ObjectId | any,
9796
options?: QueryOptions<T> | null | undefined,
9897
): Promise<Query<T, T, any, T>> {
9998
// noinspection UnnecessaryLocalVariableJS
100-
//TODO: soft delete
10199
const deleted = await super.delete(_id, options);
102-
//TODO: add backends service logic here (TO_SYNC)
103100
return deleted;
104101
}
105102
}

0 commit comments

Comments
 (0)