From 57032361ff45e448a2e092edb6d48ab2158fe1c8 Mon Sep 17 00:00:00 2001 From: ilham Date: Thu, 3 Feb 2022 02:32:39 +0700 Subject: [PATCH] add: history-deposit-profile --- src/transaction/transaction.controller.ts | 23 +++++++++++++++ src/transaction/transaction.service.ts | 36 +++++++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/transaction/transaction.controller.ts b/src/transaction/transaction.controller.ts index ab90dae..e84ab26 100644 --- a/src/transaction/transaction.controller.ts +++ b/src/transaction/transaction.controller.ts @@ -159,6 +159,29 @@ export class TransactionController { page, req.user.userId, userDestination, + 'detail', + pageSize, + ); + + return { + ...data, + statusCode: HttpStatus.OK, + message: 'success', + }; + } + + @Get('history-deposit-profile') + async getHistoryDepositUserProfile( + @Query('page') page: number, + @Query('pageSize') pageSize: number, + @Query('user-destination') userDestination: string, + @Request() req, + ) { + const data = await this.transactionService.topUpHistoryByUser( + page, + req.user.userId, + userDestination, + 'profile', pageSize, ); diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 247e4a7..e51a280 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -1041,18 +1041,48 @@ export class TransactionService { page: number, user: string, destinationUser: string, + type: string, pageSize?: number, ) { + const userData = await this.userService.findExist(user); + const baseQuery = this.transactionRepository .createQueryBuilder('transaction') - .where( + .leftJoinAndMapOne( + 'transaction.userData', + UserDetail, + 'userData', + 'userData.user = transaction.user', + ); + + if ( + userData.roles.name == 'Admin' || + userData.roles.name == 'Customer Service' || + type == 'profile' + ) { + baseQuery.where( + 'transaction.type = 0 and transaction.user_destination = :destinationId', + { + destinationId: destinationUser, + }, + ); + } else { + baseQuery.where( 'transaction.user = :id and transaction.type = 0 and transaction.user_destination = :destinationId', { id: user, destinationId: destinationUser, }, - ) - .select(['id', 'created_at as transaction_date', 'amount']) + ); + } + + baseQuery + .select([ + 'transaction.id', + 'transaction.created_at as transaction_date', + 'amount', + 'userData.name as sender_name', + ]) .orderBy('transaction.created_at', 'DESC'); const data = await baseQuery