Merge branch 'master' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-production

This commit is contained in:
Fadli 2022-09-12 12:40:11 +07:00
commit 3c7987a52c
3 changed files with 60 additions and 47 deletions

View File

@ -309,11 +309,14 @@ export class ProductService {
supplier = (await this.supplierService.findByActive()).id; supplier = (await this.supplierService.findByActive()).id;
} }
console.log(supplier, 'asldklaksd')
const baseQuery = this.productRepository const baseQuery = this.productRepository
.createQueryBuilder('product') .createQueryBuilder('product')
.leftJoin('product.sub_categories', 'sub_categories') .leftJoin('product.sub_categories', 'sub_categories')
.leftJoin('product.supplier', 'supplier')
.leftJoin('product.statusHistory', 'status_history') // .leftJoin('product.statusHistory', 'status_history')
.leftJoinAndMapOne( .leftJoinAndMapOne(
'product.currentPrice', 'product.currentPrice',
@ -321,15 +324,39 @@ export class ProductService {
'current_price', 'current_price',
'current_price.partner_id is NULL and current_price.end_date is NULL', 'current_price.partner_id is NULL and current_price.end_date is NULL',
) )
.where( .innerJoinAndMapOne(
`product.supplier_id = :supplier_id and status_history.status = 'ACTIVE' and status_history.partner_id is NULL`, 'product.currentStatus',
'product.statusHistory',
'history_status',
`history_status.status = 'ACTIVE' and history_status.deleted_at is NULL`,
{ {
supplier_id: supplier, status: 'ACTIVE',
},
)
// .where(
// `product.supplier_id = :supplier_id`,
// {
// supplier_id: supplier,
// },
// )
.where(
`history_status.partner_id is NULL`,
{
partner_id: null,
},
)
.andWhere(
'supplier.status = TRUE',
{
status: true,
}, },
) )
.select(['product.id']) .select(['product.id'])
.addSelect(['product.name', 'product.code', 'sub_categories.name']) .addSelect(['product.name', 'product.code', 'sub_categories.name'])
.addSelect('(current_price.price + current_price.mark_up_price) as price') .addSelect('(current_price.price + current_price.mark_up_price) as price')
.addSelect('product.supplier_id', 'supplier')
.addSelect('supplier.status', 'status')
.addSelect('history_status.partner_id', 'partner')
.orderBy('price', 'ASC') .orderBy('price', 'ASC')
.distinct(); .distinct();
@ -380,11 +407,16 @@ export class ProductService {
const baseQuery = await this.productRepository const baseQuery = await this.productRepository
.createQueryBuilder('product') .createQueryBuilder('product')
.leftJoin('product.sub_categories', 'sub_categories') .leftJoin('product.sub_categories', 'sub_categories')
.leftJoinAndSelect( .leftJoin('product.supplier', 'supplier')
'product.supplier', // .leftJoinAndSelect(
'supplier', // 'product.supplier',
'supplier.status = true', // 'supplier',
) // 'supplier.status = true',
// {
// status: true
// }
//
// )
.innerJoinAndMapOne( .innerJoinAndMapOne(
'product.currentPrice', 'product.currentPrice',
'product.priceHistory', 'product.priceHistory',
@ -409,11 +441,15 @@ export class ProductService {
.where(`history_status.status = 'ACTIVE'`, { .where(`history_status.status = 'ACTIVE'`, {
status: 'ACTIVE', status: 'ACTIVE',
}) })
.andWhere('supplier.status = TRUE', {
status: true
})
.select(['product.id']) .select(['product.id'])
.addSelect([ .addSelect([
'product.name', 'product.name',
'product.code', 'product.code',
'product.type', 'product.type',
'product.supplier_id',
'sub_categories.name', 'sub_categories.name',
'current_price.admin_price as admin_price', 'current_price.admin_price as admin_price',
'current_price.mark_up_price as markup_price', 'current_price.mark_up_price as markup_price',
@ -505,16 +541,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 +564,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(