From e849c1cfdbfd9011b57f4809146199e15cc33fc0 Mon Sep 17 00:00:00 2001 From: Fadli Date: Sun, 21 Aug 2022 00:37:19 +0700 Subject: [PATCH 1/2] - fix when all the product is not active --- src/transaction/transaction.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index be86fb7..bdf7273 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -310,7 +310,7 @@ export class TransactionService { 'prepaid', ); - if (productData.status == 'NOT ACTIVE') { + if (!productData.status.includes('ACTIVE')) { throw new HttpException( { statusCode: HttpStatus.INTERNAL_SERVER_ERROR, @@ -467,7 +467,7 @@ export class TransactionService { 'prepaid', ); - if (productData.status == 'NOT ACTIVE') { + if (!productData.status.includes('ACTIVE')) { throw new HttpException( { statusCode: HttpStatus.INTERNAL_SERVER_ERROR, From 78da6bae131a9feda864f7e9735614ccae49dfaf Mon Sep 17 00:00:00 2001 From: Fadli Date: Sun, 21 Aug 2022 01:15:25 +0700 Subject: [PATCH 2/2] - fix getting the product that only active --- src/product/product.service.ts | 24 ++++++++++++++++++++++++ src/transaction/transaction.service.ts | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 14ba472..8457093 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -429,6 +429,30 @@ export class ProductService { } } + async findOneActive(code: string, type: string) { + try { + return await this.productRepository.findOneOrFail({ + relations: ['supplier'], + where: { + code: code, + status: 'ACTIVE', + }, + }); + } catch (e) { + if (e instanceof EntityNotFoundError) { + throw new HttpException( + { + statusCode: HttpStatus.NOT_FOUND, + error: 'Product not found', + }, + HttpStatus.NOT_FOUND, + ); + } else { + throw e; + } + } + } + async findOneById(id: string) { try { return await this.productRepository.findOneOrFail({ diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index bdf7273..8399508 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -333,7 +333,7 @@ export class TransactionService { ); //GET PRODUCT - const product = await this.productService.findOne( + const product = await this.productService.findOneActive( orderTransactionDto.productCode, 'prepaid' ); @@ -484,7 +484,7 @@ export class TransactionService { ); //GET PRODUCT AND PRICE - const product = await this.productService.findOne( + const product = await this.productService.findOneActive( orderTransactionDto.productCode, 'prepaid', );