- fix order-prod and order-stg if suppliers have same code product

This commit is contained in:
Fadli 2022-09-07 16:36:24 +07:00
parent 399c6ff9e4
commit 6d9ce6f8ec
3 changed files with 11 additions and 34 deletions

View File

@ -505,16 +505,14 @@ export class ProductService {
async findOneActive( async findOneActive(
code: string, code: string,
type: string, type: string,
roles: string, productId: string
supplierId: string,
) { ) {
if (roles == 'Retail') {
try { try {
return await this.productRepository.findOneOrFail({ return await this.productRepository.findOneOrFail({
relations: ['supplier'], relations: ['supplier'],
where: { where: {
code: code, code: code,
supplier: supplierId, id: productId
}, },
}); });
} catch (e) { } catch (e) {
@ -530,28 +528,7 @@ export class ProductService {
throw e; 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;
}
}
}
} }
async findOneById(id: string) { async findOneById(id: string) {

View File

@ -1,6 +1,10 @@
import { IsNotEmpty, IsOptional } from 'class-validator'; import { IsNotEmpty, IsOptional } from 'class-validator';
export class OrderTransactionDto { export class OrderTransactionDto {
@IsNotEmpty()
productId: string;
@IsNotEmpty() @IsNotEmpty()
productCode: string; productCode: string;

View File

@ -335,14 +335,13 @@ export class TransactionService {
currentUser.username, currentUser.username,
); );
const supplierData = await this.supplierService.findByCode('IRS'); // const supplierData = await this.supplierService.findByCode('IRS');
//GET PRODUCT //GET PRODUCT
const product = await this.productService.findOneActive( const product = await this.productService.findOneActive(
orderTransactionDto.productCode, orderTransactionDto.productCode,
'prepaid', 'prepaid',
userData.roles.name, orderTransactionDto.productId
supplierData.id
); );
const product_price = await this.productHistoryPriceService.findOne( const product_price = await this.productHistoryPriceService.findOne(
@ -491,16 +490,13 @@ export class TransactionService {
currentUser.username, currentUser.username,
); );
const supplierData = await this.supplierService.findByCode('IRS'); // const supplierData = await this.supplierService.findByCode('IRS');
//GET PRODUCT AND PRICE //GET PRODUCT AND PRICE
const product = await this.productService.findOneActive( const product = await this.productService.findOneActive(
orderTransactionDto.productCode, orderTransactionDto.productCode,
'prepaid', 'prepaid',
userData.roles.name, orderTransactionDto.productId
supplierData.id
); );
const supplier = await this.supplierService.findByCode( const supplier = await this.supplierService.findByCode(