feat: add set status membership endpoint

This commit is contained in:
caturbgs 2021-12-14 20:38:23 +07:00
parent cab057f683
commit 3835b0ee35
2 changed files with 28 additions and 0 deletions

View File

@ -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') @Put(':id')
async update( async update(
@Param('id', ParseUUIDPipe) id: string, @Param('id', ParseUUIDPipe) id: string,

View File

@ -261,6 +261,22 @@ export class UsersService {
return userData; 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) { async remove(id: string) {
try { try {
await this.usersRepository.findOneOrFail(id); await this.usersRepository.findOneOrFail(id);