diff --git a/src/product/product.service.ts b/src/product/product.service.ts index f6f2dd3..e9e8f82 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -466,26 +466,53 @@ export class ProductService { } } - async findOneActive(code: string, type: string) { - try { - return await this.productRepository.findOneOrFail({ - relations: ['supplier'], - where: { - code: code, - }, - }); - } catch (e) { - if (e instanceof EntityNotFoundError) { - throw new HttpException( - { - statusCode: HttpStatus.NOT_FOUND, - error: 'Product not found', - }, - HttpStatus.NOT_FOUND, - ); - } else { - throw e; + async findOneActive(code: string, type: string, roles: string, supplierId: string) { + if (roles == "Retail") { + try { + return await this.productRepository.findOneOrFail({ + relations: ['supplier'], + where: { + code: code, + supplier: supplierId + }, + }); + } catch (e) { + if (e instanceof EntityNotFoundError) { + throw new HttpException( + { + statusCode: HttpStatus.NOT_FOUND, + error: 'Product not found', + }, + HttpStatus.NOT_FOUND, + ); + } else { + throw e; + } } + } else { + + + try { + return await this.productRepository.findOneOrFail({ + relations: ['supplier'], + where: { + code: code, + }, + }); + } catch (e) { + if (e instanceof EntityNotFoundError) { + throw new HttpException( + { + statusCode: HttpStatus.NOT_FOUND, + error: 'Product not found', + }, + HttpStatus.NOT_FOUND, + ); + } else { + throw e; + } + } + } } diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 652acec..332f73e 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -332,11 +332,15 @@ export class TransactionService { currentUser.username, ); - //GET PRODUCT - const product = await this.productService.findOneActive( - orderTransactionDto.productCode, - 'prepaid' - ); + const supplierData = await this.supplierService.findByCode('IRS'); + + //GET PRODUCT + const product = await this.productService.findOneActive( + orderTransactionDto.productCode, + 'prepaid', + userData.roles.name, + supplierData.id + ); const product_price = await this.productHistoryPriceService.findOne( product.id, @@ -483,10 +487,16 @@ export class TransactionService { currentUser.username, ); + const supplierData = await this.supplierService.findByCode('IRS'); + + + //GET PRODUCT AND PRICE const product = await this.productService.findOneActive( orderTransactionDto.productCode, 'prepaid', + userData.roles.name, + supplierData.id ); const supplier = await this.supplierService.findByCode(