From 5ef41a82dcc4540c1789ff04f472b2e49a8944f6 Mon Sep 17 00:00:00 2001 From: ilham Date: Mon, 20 Dec 2021 10:47:19 +0700 Subject: [PATCH 1/2] fix: transaction controller --- src/transaction/transaction.controller.ts | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/transaction/transaction.controller.ts b/src/transaction/transaction.controller.ts index b3e472c..25118c4 100644 --- a/src/transaction/transaction.controller.ts +++ b/src/transaction/transaction.controller.ts @@ -116,13 +116,15 @@ export class TransactionController { @Get('deposit-return') async findDepositReturn(@Query('page') page: number, @Request() req) { - const data = await this.transactionService.getAllDepositReturnFromUser( - req.user.userId, - page, - ); + const [data, count] = + await this.transactionService.getAllDepositReturnFromUser( + req.user.userId, + page, + ); return { - ...data, + data, + count, statusCode: HttpStatus.OK, message: 'success', }; @@ -133,13 +135,15 @@ export class TransactionController { @Query('page') page: number, @Request() req, ) { - const data = await this.transactionService.getAllDepositReturnToUser( - req.user.userId, - page, - ); + const [data, count] = + await this.transactionService.getAllDepositReturnToUser( + req.user.userId, + page, + ); return { - ...data, + data, + count, statusCode: HttpStatus.OK, message: 'success', }; From 6c24f6784da752b39e15dc1062c4d31fc432985d Mon Sep 17 00:00:00 2001 From: ilham Date: Mon, 20 Dec 2021 12:13:48 +0700 Subject: [PATCH 2/2] add: change password --- src/users/users.controller.ts | 13 +++++++++++++ src/users/users.service.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index c7d614b..42c581f 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -207,6 +207,19 @@ export class UsersController { }; } + @Put('change-password/:id') + async updatePassword( + @Param('id', ParseUUIDPipe) id: string, + @Request() req, + @Body() updateUserDto: UpdateUserDto, + ) { + return { + data: await this.usersService.updatePassword(id, updateUserDto, req.user), + statusCode: HttpStatus.OK, + message: 'success', + }; + } + @Delete(':id') async remove(@Param('id', ParseUUIDPipe) id: string) { await this.usersService.remove(id); diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 38fb9e9..987c3bb 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -313,6 +313,34 @@ export class UsersService { return userData; } + async updatePassword( + id: string, + updateUserDto: UpdateUserDto, + currentUser: any, + ) { + try { + const dataUser = await this.usersRepository.findOneOrFail(id); + dataUser.password = await hashPassword( + updateUserDto.password, + dataUser.salt, + ); + const result = await this.usersRepository.save(dataUser); + return dataUser; + } catch (e) { + if (e instanceof EntityNotFoundError) { + throw new HttpException( + { + statusCode: HttpStatus.NOT_FOUND, + error: 'User not found', + }, + HttpStatus.NOT_FOUND, + ); + } else { + throw e; + } + } + } + setStatus = async (id: string, type: string) => { const userData = new User();