Skip to content

Commit fe5fb2d

Browse files
committed
2 parents a195092 + 7b5515d commit fe5fb2d

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

src/management/identities/identities.controller.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,33 @@ export class IdentitiesController extends AbstractController {
177177
@Body() body: IdentitiesUpdateDto,
178178
@Res() res: Response,
179179
): Promise<Response> {
180-
try {
181-
const data = await this._service.update(_id, body);
182-
return res.status(HttpStatus.OK).json({
183-
statusCode: HttpStatus.OK,
184-
data,
185-
});
186-
} catch (error) {
187-
return res.status(HttpStatus.BAD_REQUEST).json({
188-
statusCode: HttpStatus.BAD_REQUEST,
189-
message: error.message,
190-
validations: error.validations,
191-
});
180+
const data = await this._service.update(_id, body);
181+
return res.status(HttpStatus.OK).json({
182+
statusCode: HttpStatus.OK,
183+
data,
184+
});
185+
}
186+
187+
@Patch(':_id([0-9a-fA-F]{24})/state')
188+
@ApiParam({ name: '_id', type: String })
189+
@ApiUpdateDecorator(IdentitiesUpdateDto, IdentitiesDto)
190+
public async updateState(
191+
@Param('_id', ObjectIdValidationPipe) _id: Types.ObjectId,
192+
@Body() body: IdentitiesUpdateDto,
193+
@Res() res: Response,
194+
): Promise<Response> {
195+
const identity = await this._service.findById(_id);
196+
if (!identity) {
197+
throw new BadRequestException('Identity not found');
192198
}
199+
if (identity.state !== IdentityState.TO_VALIDATE) {
200+
throw new BadRequestException("La validation de l'identité est déjà complétée.");
201+
}
202+
const data = await this._service.updateState(_id, body.state);
203+
return res.status(HttpStatus.OK).json({
204+
statusCode: HttpStatus.OK,
205+
data,
206+
});
193207
}
194208

195209
@Delete(':_id([0-9a-fA-F]{24})')

src/management/identities/identities.service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,25 @@ export class IdentitiesService extends AbstractServiceSchema {
9292
throw error; // Rethrow the original error if it's not one of the handled types.
9393
}
9494
}
95+
if (update.state === IdentityState.TO_COMPLETE) {
96+
update = { ...update, state: IdentityState.TO_VALIDATE };
97+
}
98+
console.log(update);
9599
//update.state = IdentityState.TO_VALIDATE;
96100
const updated = await super.update(_id, update, options);
97101
//TODO: add backends service logic here (TO_SYNC)
98102
return updated;
99103
}
100104

105+
public async updateState<T extends AbstractSchema | Document>(
106+
_id: Types.ObjectId | any,
107+
state: IdentityState,
108+
options?: QueryOptions<T> & { rawResult: true },
109+
): Promise<ModifyResult<Query<T, T, any, T>>> {
110+
const updated = await super.update(_id, { state }, options);
111+
return updated;
112+
}
113+
101114
public async delete<T extends AbstractSchema | Document>(
102115
_id: Types.ObjectId | any,
103116
options?: QueryOptions<T> | null | undefined,

0 commit comments

Comments
 (0)