From 7fdcf030438aef27ee3c94bba0a6a1e9b2c273eb Mon Sep 17 00:00:00 2001 From: ilham Date: Sun, 26 Dec 2021 11:21:04 +0700 Subject: [PATCH 1/6] fix: change username for partner user --- src/users/partner/partner.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/users/partner/partner.service.ts b/src/users/partner/partner.service.ts index cf2422f..c2ae800 100644 --- a/src/users/partner/partner.service.ts +++ b/src/users/partner/partner.service.ts @@ -62,7 +62,7 @@ export class PartnerService { const dataUser = new CreateUserDto(); - dataUser.username = `admin_${partnerData.name}`; + dataUser.username = `admin_${partnerData.code}`; dataUser.name = partnerData.name; dataUser.phone_number = partnerData.phone_number; dataUser.roleId = '21dceea2-416e-4b55-b74c-12605e1f8d1b'; From 36f343a306e18602e7aaeffd989383ee74fc30a3 Mon Sep 17 00:00:00 2001 From: ilham Date: Sun, 26 Dec 2021 11:27:23 +0700 Subject: [PATCH 2/6] add: update password partner --- src/users/users.controller.ts | 15 ++++++++++++++- src/users/users.service.ts | 34 +++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index a127b27..ba68801 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -230,7 +230,20 @@ export class UsersController { @Body() updateUserDto: UpdateUserDto, ) { return { - data: await this.usersService.updatePassword(id, updateUserDto, req.user), + data: await this.usersService.updatePassword(id, updateUserDto), + statusCode: HttpStatus.OK, + message: 'success', + }; + } + + @Put('change-password-partner/:id') + async updatePasswordPartner( + @Param('id', ParseUUIDPipe) id: string, + @Request() req, + @Body() updateUserDto: UpdateUserDto, + ) { + return { + data: await this.usersService.updatePassword(id, updateUserDto), statusCode: HttpStatus.OK, message: 'success', }; diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 197d5e9..c34752f 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -358,11 +358,7 @@ export class UsersService { return userData; } - async updatePassword( - id: string, - updateUserDto: UpdateUserDto, - currentUser: any, - ) { + async updatePassword(id: string, updateUserDto: UpdateUserDto) { try { const dataUser = await this.usersRepository.findOneOrFail(id); dataUser.password = await hashPassword( @@ -386,6 +382,34 @@ export class UsersService { } } + async updatePasswordPartner(id: string, updateUserDto: UpdateUserDto) { + try { + const dataUser = await this.usersRepository.findOneOrFail({ + where: { + partner: 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(); From 1bfd132a2ee2458ae5b2070258d44ef0d1eb4c68 Mon Sep 17 00:00:00 2001 From: ilham Date: Sun, 26 Dec 2021 12:02:56 +0700 Subject: [PATCH 3/6] fix: update and create product by csv --- src/product/product.service.ts | 38 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 55573ef..e4bcfb0 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -1,5 +1,5 @@ import { HttpException, HttpStatus } from '@nestjs/common'; -import { EntityNotFoundError, Repository } from 'typeorm'; +import { EntityNotFoundError, IsNull, Repository } from 'typeorm'; import { Product } from './entities/product.entity'; import { InjectRepository } from '@nestjs/typeorm'; import { CreateProductDto } from './dto/product/create-product.dto'; @@ -87,27 +87,37 @@ export class ProductService { partner: partnerData.id, }, }); + + } else { dataHistoryPrice = await this.productHistoryPrice.findOne({ product: productData, + partner: IsNull(), }); } if (!dataHistoryPrice) { - return; + await this.productHistoryPrice.insert({ + product: productData, + mark_up_price: it[4], + price: it[3], + type: productType.NORMAL, + startDate: new Date(), + partner: it[6] != '-' ? partnerData : null, + }); + } else { + dataHistoryPrice.endDate = new Date(); + await this.productHistoryPrice.save(dataHistoryPrice); + + await this.productHistoryPrice.insert({ + product: productData, + mark_up_price: it[4], + price: it[3], + type: productType.NORMAL, + startDate: new Date(), + partner: it[6] != '-' ? partnerData : null, + }); } - - dataHistoryPrice.endDate = new Date(); - await this.productHistoryPrice.save(dataHistoryPrice); - - await this.productHistoryPrice.insert({ - product: productData, - mark_up_price: it[4], - price: it[3], - type: productType.NORMAL, - startDate: new Date(), - partner: it[6] != '-' ? partnerData : null, - }); } else { let partnerData; if (it[6] != '-' && it[6] != '') { From 18525e6b41086f65caabfd55282ab138e8756170 Mon Sep 17 00:00:00 2001 From: ilham Date: Sun, 26 Dec 2021 13:37:33 +0700 Subject: [PATCH 4/6] fix: transaction partner --- src/transaction/transaction.service.ts | 88 ++++++++++++++------------ 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index dc64cee..8653d64 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -319,25 +319,8 @@ export class TransactionService { ); let supervisorData = []; - let profit = product_price.mark_up_price; - if (!userData.partner) { - //GET SALES - supervisorData = await this.calculateCommission( - supervisorData, - profit, - userData, - ); - profit = supervisorData - .map((item) => { - return item.credit; - }) - .reduce((prev, curr) => { - return prev + curr; - }, 0); - } - //GET COA const coaAccount = await this.coaService.findByUser( userData.id, @@ -360,6 +343,29 @@ export class TransactionService { `${coaType[coaType.EXPENSE]}-SYSTEM`, ); + if (!userData.partner) { + //GET SALES + supervisorData = await this.calculateCommission( + supervisorData, + profit, + userData, + ); + profit = supervisorData + .map((item) => { + return item.credit; + }) + .reduce((prev, curr) => { + return prev + curr; + }, 0); + + supervisorData = supervisorData.concat([ + { + coa_id: coaExpense.id, + debit: profit, + }, + ]); + } + if (coaAccount.amount <= product.price) { throw new HttpException( { @@ -406,10 +412,6 @@ export class TransactionService { coa_id: coaSales.id, credit: product_price.mark_up_price + product_price.price, }, - { - coa_id: coaExpense.id, - debit: userData.partner ? 0 : profit, - }, ].concat(supervisorData), }); }); @@ -678,22 +680,6 @@ export class TransactionService { let profit = product_price.mark_up_price; - if (!userData.partner) { - //GET SALES - supervisorData = await this.calculateCommission( - supervisorData, - profit, - userData, - ); - profit = supervisorData - .map((item) => { - return item.credit; - }) - .reduce((prev, curr) => { - return prev + curr; - }, 0); - } - //GET COA const coaAccount = await this.coaService.findByUser( userData.id, @@ -716,6 +702,29 @@ export class TransactionService { `${coaType[coaType.EXPENSE]}-SYSTEM`, ); + if (!userData.partner) { + //GET SALES + supervisorData = await this.calculateCommission( + supervisorData, + profit, + userData, + ); + profit = supervisorData + .map((item) => { + return item.credit; + }) + .reduce((prev, curr) => { + return prev + curr; + }, 0); + + supervisorData = supervisorData.concat([ + { + coa_id: coaExpense.id, + debit: profit, + }, + ]); + } + try { await this.connection.transaction(async (manager) => { await manager.save(dataTransaction); @@ -742,10 +751,6 @@ export class TransactionService { coa_id: coaSales.id, credit: product_price.mark_up_price + product_price.price, }, - { - coa_id: coaExpense.id, - debit: userData.partner ? 0 : profit, - }, ].concat(supervisorData), }); }); @@ -1119,3 +1124,4 @@ export class TransactionService { return transaction; } } + From 342c9902caf3ea74708bee241b4c10d9d2b5fdf2 Mon Sep 17 00:00:00 2001 From: ilham Date: Sun, 26 Dec 2021 15:09:42 +0700 Subject: [PATCH 5/6] fix: gett history transaction --- src/transaction/transaction.service.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 8653d64..e94d45a 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -773,7 +773,7 @@ export class TransactionService { }) .leftJoin('transaction.product_price', 'product_price') .leftJoin('product_price.product', 'product') - .addSelect('product_price.mark_up_price', 'mark_up_price') + .addSelect('transaction.amount', 'mark_up_price') .addSelect('product.name', 'name') .addSelect('product.id', 'product_id'); @@ -1124,4 +1124,3 @@ export class TransactionService { return transaction; } } - From aa8764ff2b26fa1262c5c395274796b72fd3066d Mon Sep 17 00:00:00 2001 From: ilham Date: Sun, 26 Dec 2021 23:01:44 +0700 Subject: [PATCH 6/6] fix: callback transaction --- src/product/history-price/history-price.service.ts | 7 ++++++- src/transaction/entities/transactions.entity.ts | 10 ++++++++++ src/transaction/ppob_callback.controller.ts | 8 +++++++- src/transaction/transaction.service.ts | 9 ++++++--- src/users/users.service.ts | 7 ++++++- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/product/history-price/history-price.service.ts b/src/product/history-price/history-price.service.ts index 694dedd..698b369 100644 --- a/src/product/history-price/history-price.service.ts +++ b/src/product/history-price/history-price.service.ts @@ -42,7 +42,12 @@ export class ProductHistoryPriceService { async findById(id: string) { try { - return await this.productHistoryPriceService.findOneOrFail(id); + return await this.productHistoryPriceService.findOneOrFail({ + where: { + id: id, + }, + relations: ['product'], + }); } catch (e) { if (e instanceof EntityNotFoundError) { throw new HttpException( diff --git a/src/transaction/entities/transactions.entity.ts b/src/transaction/entities/transactions.entity.ts index c9b4c74..ba5c342 100644 --- a/src/transaction/entities/transactions.entity.ts +++ b/src/transaction/entities/transactions.entity.ts @@ -58,6 +58,16 @@ export class Transactions extends BaseModel { }) phone_number: string; + @Column({ + nullable: true, + }) + request_json: string; + + @Column({ + nullable: true, + }) + callback_json: string; + mark_up_price: number; userData: UserDetail; diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index e7064ec..f208388 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -13,6 +13,7 @@ import { import { TransactionService } from './transaction.service'; import { DistributeTransactionDto } from './dto/distribute-transaction.dto'; import { FastifyRequest } from 'fastify'; +import { Public } from '../auth/public.decorator'; @Controller({ path: 'ppob_callback', @@ -23,6 +24,7 @@ export class PpobCallbackController { constructor(private readonly transactionService: TransactionService) {} + @Public() @Get() async get(@Req() request: FastifyRequest) { const response = request.query; @@ -30,12 +32,16 @@ export class PpobCallbackController { if (response['statuscode'] == 2) { //TODO: UPDATE GAGAL const updateTransaction = - await this.transactionService.callbackOrderFailed(response['clientid']); + await this.transactionService.callbackOrderFailed( + response['clientid'], + response, + ); } else { //TODO: UPDATE BERHASIL const updateTransaction = await this.transactionService.callbackOrderSuccess( response['clientid'], + response, ); } this.logger.log({ diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index e94d45a..bbcfcc3 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -647,24 +647,27 @@ export class TransactionService { return transactionData; } - async callbackOrderFailed(supplier_trx_id: string) { + async callbackOrderFailed(supplier_trx_id: string, callback: any) { const dataTransaction = await this.transactionRepository.findOne({ where: { supplier_trx_id: supplier_trx_id, }, }); dataTransaction.status = statusTransaction.FAILED; + dataTransaction.callback_json = callback; await this.transactionRepository.save(dataTransaction); } - async callbackOrderSuccess(supplier_trx_id: string) { + async callbackOrderSuccess(supplier_trx_id: string, callback: any) { const dataTransaction = await this.transactionRepository.findOne({ where: { supplier_trx_id: supplier_trx_id, }, + relations: ['product_price'], }); dataTransaction.status = statusTransaction.FAILED; + dataTransaction.callback_json = callback; const userData = await this.userService.findExist(dataTransaction.user); @@ -702,7 +705,7 @@ export class TransactionService { `${coaType[coaType.EXPENSE]}-SYSTEM`, ); - if (!userData.partner) { + if (userData.partner) { //GET SALES supervisorData = await this.calculateCommission( supervisorData, diff --git a/src/users/users.service.ts b/src/users/users.service.ts index c34752f..939af19 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -220,7 +220,12 @@ export class UsersService { async findExist(id: string) { try { - return await this.usersRepository.findOneOrFail(id); + return await this.usersRepository.findOneOrFail({ + where: { + id: id, + }, + relations: ['superior'], + }); } catch (e) { if (e instanceof EntityNotFoundError) { throw new HttpException(