diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index f8e4e9c..4c15b31 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -191,6 +191,18 @@ export class UsersController { }; } + @Get(':id/:type') + async setStatusMembership( + @Param('id', ParseUUIDPipe) id: string, + @Param('type') type: string, + ) { + return { + data: await this.usersService.setStatus(id, type), + statusCode: HttpStatus.CREATED, + message: 'success', + }; + } + @Put(':id') async update( @Param('id', ParseUUIDPipe) id: string, diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 743e04c..71d2bfb 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -261,6 +261,22 @@ export class UsersService { return userData; } + setStatus = async (id: string, type: string) => { + const userData = new User(); + + if (type === 'active') { + userData.isActive = true; + } else { + userData.isActive = false; + } + + await this.connection.transaction(async (manager) => { + await manager.update(User, { id: id }, userData); + }); + + return userData; + }; + async remove(id: string) { try { await this.usersRepository.findOneOrFail(id);