Skip to content

Commit 3ebc563

Browse files
committed
Enhance lifecycle state management: add icon and color properties to states, implement updateLifecycle method in service, and update DTOs accordingly
1 parent da9a4cb commit 3ebc563

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

defaults/lifecycle/states.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ states:
44
label: "En Attente"
55
description: "supannRessourceEtat : {COMPTE} A SupannAnticipe"
66
icon: "mdi-account-clock"
7+
color: "#f0ad4e"
78

89
# PROV -> supannResourceEtat : {COMPTE} A SupannSursis et supannRessourceEtatDate: Date de passage en PROV
910
- key: P
1011
label: "Provisoire"
1112
description: "supannResourceEtat : {COMPTE} A SupannSursis et supannRessourceEtatDate: Date de passage en PROV"
1213
icon: "mdi-account-alert"
14+
color: "#5bc0de"
1315

1416
# A Détruire -> supannRessourceEtat : {COMPTE} I SupannSupprCompte
1517
- key: D
1618
label: "A Détruire"
1719
description: "supannRessourceEtat : {COMPTE} I SupannSupprCompte"
1820
icon: "mdi-account-remove"
21+
color: "#d9534f"
1922

2023
# Verrouillé -> supannRessourceEtat : {COMPTE} S SupannVerrouille
2124
- key: V
2225
label: "Verrouillé"
2326
description: "supannRessourceEtat : {COMPTE} S SupannVerrouille"
2427
icon: "mdi-account-lock"
28+
color: "#292b2c"

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,25 @@ export class IdentitiesCrudController extends AbstractController {
264264
});
265265
}
266266

267+
@Patch(':_id([0-9a-fA-F]{24})/lifecycle')
268+
@ApiParam({ name: '_id', type: String })
269+
@ApiUpdateDecorator(IdentitiesUpdateDto, IdentitiesDto)
270+
public async updateLifecycle(
271+
@Param('_id', ObjectIdValidationPipe) _id: Types.ObjectId,
272+
@Body() body: IdentitiesUpdateDto,
273+
@Res() res: Response,
274+
): Promise<Response> {
275+
const identity = await this._service.findById<Identities>(_id);
276+
if (!identity) {
277+
throw new BadRequestException('Identity not found');
278+
}
279+
const data = await this._service.updateLifecycle(_id, body.lifecycle);
280+
return res.status(HttpStatus.OK).json({
281+
statusCode: HttpStatus.OK,
282+
data,
283+
});
284+
}
285+
267286
@Patch('state')
268287
@ApiOperation({ summary: "Met à jour l'état d'une ou plusieurs <Identitées> en masse" })
269288
public async updateStateMany(

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IdentityState } from '~/management/identities/_enums/states.enum';
66
import { Identities } from '~/management/identities/_schemas/identities.schema';
77
import { BadRequestException, HttpException } from '@nestjs/common';
88
import { CountOptions } from 'mongodb';
9+
import { IdentityLifecycleDefault, IdentityLifecycleState } from './_enums/lifecycle.enum';
910

1011
export const COUNT_ALL_MAX_ITERATIONS = 500;
1112

@@ -128,6 +129,15 @@ export class IdentitiesCrudService extends AbstractIdentitiesService {
128129
return await this.generateFingerprint(updated as unknown as Identities);
129130
}
130131

132+
public async updateLifecycle<T extends AbstractSchema | Document>(
133+
_id: Types.ObjectId | any,
134+
lifecycle: IdentityLifecycleDefault | string,
135+
options?: QueryOptions<T> & { rawResult: true },
136+
): Promise<ModifyResult<Query<T, T, any, T>>> {
137+
const updated = await super.update(_id, { lifecycle }, options);
138+
return updated;
139+
}
140+
131141
public async updateState<T extends AbstractSchema | Document>(
132142
_id: Types.ObjectId | any,
133143
state: IdentityState,
@@ -136,6 +146,7 @@ export class IdentitiesCrudService extends AbstractIdentitiesService {
136146
const updated = await super.update(_id, { state }, options);
137147
return updated;
138148
}
149+
139150
public async updateStateMany<T extends AbstractSchema | Document>(body: {
140151
ids: Types.ObjectId[];
141152
targetState: IdentityState;

src/management/lifecycle/_dto/config-states.dto.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ export class LifecycleStateDTO {
4747
required: false,
4848
})
4949
public icon?: string;
50+
51+
@IsOptional()
52+
@IsString()
53+
@ApiProperty({
54+
type: String,
55+
description: 'Couleur associée à l\'état (optionnel, en hexadécimal)',
56+
example: '#f0ad4e',
57+
required: false,
58+
})
59+
public color?: string;
5060
}
5161

5262
/**

0 commit comments

Comments
 (0)