- fix getting the product that only active

This commit is contained in:
Fadli 2022-08-21 01:15:25 +07:00
parent e849c1cfdb
commit 78da6bae13
2 changed files with 26 additions and 2 deletions

View File

@ -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) { async findOneById(id: string) {
try { try {
return await this.productRepository.findOneOrFail({ return await this.productRepository.findOneOrFail({

View File

@ -333,7 +333,7 @@ export class TransactionService {
); );
//GET PRODUCT //GET PRODUCT
const product = await this.productService.findOne( const product = await this.productService.findOneActive(
orderTransactionDto.productCode, orderTransactionDto.productCode,
'prepaid' 'prepaid'
); );
@ -484,7 +484,7 @@ export class TransactionService {
); );
//GET PRODUCT AND PRICE //GET PRODUCT AND PRICE
const product = await this.productService.findOne( const product = await this.productService.findOneActive(
orderTransactionDto.productCode, orderTransactionDto.productCode,
'prepaid', 'prepaid',
); );