From f0be8ca0677bfd09db4f2e6f587fa13a6d098bcf Mon Sep 17 00:00:00 2001 From: Muhammad Fadli Date: Fri, 28 Apr 2023 19:13:23 +0700 Subject: [PATCH 1/3] - fix get product partner hide markup price --- src/product/product.service.ts | 69 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index b20edbb..59ed630 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -405,7 +405,8 @@ export class ProductService { ); } - const baseQuery = await this.productRepository + const baseQuery = user.roles.name == 'Admin' ? + await this.productRepository .createQueryBuilder('product') .leftJoin('product.sub_categories', 'sub_categories') .leftJoin('product.supplier', 'supplier') @@ -458,6 +459,71 @@ export class ProductService { 'current_price.price as price', ]) .addSelect('history_status.status', 'status') + .distinct() + // .addSelect( + // '(current_price.price + current_price.mark_up_price) as price', + // ); + + // if ( + // subCategories != 'null' && + // subCategories && + // subCategories != 'undefined' + // ) { + // baseQuery.where('product.sub_categories_id = :id', { + // id: subCategories, + // }); + // } +: + await this.productRepository + .createQueryBuilder('product') + .leftJoin('product.sub_categories', 'sub_categories') + .leftJoin('product.supplier', 'supplier') + // .leftJoinAndSelect( + // 'product.supplier', + // 'supplier', + // 'supplier.status = true', + // { + // status: true + // } + // + // ) + .innerJoinAndMapOne( + 'product.currentPrice', + 'product.priceHistory', + 'current_price', + 'current_price.partner_id = :id_partner and current_price.end_date is NULL', + { + id_partner: user.partner.id, + }, + ) + .innerJoinAndMapOne( + 'product.currentStatus', + 'product.statusHistory', + 'history_status', + 'history_status.partner_id = :id_partner and history_status.deleted_at is NULL', + { + id_partner: user.partner.id, + }, + ) + // .where(`history_status.partner_id = :id_partner`, { + // partner: user.partner.id, + // }) + .where(`history_status.status = 'ACTIVE'`, { + status: 'ACTIVE', + }) + .andWhere('supplier.status = TRUE', { + status: true + }) + .select(['product.id']) + .addSelect([ + 'product.name', + 'product.code', + 'product.type', + 'product.supplier_id', + 'sub_categories.name', + 'current_price.price as price', + ]) + .addSelect('history_status.status', 'status') .distinct(); // .addSelect( // '(current_price.price + current_price.mark_up_price) as price', @@ -472,7 +538,6 @@ export class ProductService { // id: subCategories, // }); // } - if (subCategories && filterSubCategories.length > 0) { baseQuery .where('product.sub_categories_id IN (:...subCategoryId)', { From 0dd35e0baa1d249f96af16656316bd93edf580e9 Mon Sep 17 00:00:00 2001 From: Muhammad Fadli Date: Fri, 28 Apr 2023 19:47:21 +0700 Subject: [PATCH 2/3] - fix get product partner hide markup price --- src/product/product.service.ts | 73 +++------------------------------- 1 file changed, 6 insertions(+), 67 deletions(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 59ed630..1ca6398 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -405,8 +405,7 @@ export class ProductService { ); } - const baseQuery = user.roles.name == 'Admin' ? - await this.productRepository + const baseQuery = await this.productRepository .createQueryBuilder('product') .leftJoin('product.sub_categories', 'sub_categories') .leftJoin('product.supplier', 'supplier') @@ -459,71 +458,6 @@ export class ProductService { 'current_price.price as price', ]) .addSelect('history_status.status', 'status') - .distinct() - // .addSelect( - // '(current_price.price + current_price.mark_up_price) as price', - // ); - - // if ( - // subCategories != 'null' && - // subCategories && - // subCategories != 'undefined' - // ) { - // baseQuery.where('product.sub_categories_id = :id', { - // id: subCategories, - // }); - // } -: - await this.productRepository - .createQueryBuilder('product') - .leftJoin('product.sub_categories', 'sub_categories') - .leftJoin('product.supplier', 'supplier') - // .leftJoinAndSelect( - // 'product.supplier', - // 'supplier', - // 'supplier.status = true', - // { - // status: true - // } - // - // ) - .innerJoinAndMapOne( - 'product.currentPrice', - 'product.priceHistory', - 'current_price', - 'current_price.partner_id = :id_partner and current_price.end_date is NULL', - { - id_partner: user.partner.id, - }, - ) - .innerJoinAndMapOne( - 'product.currentStatus', - 'product.statusHistory', - 'history_status', - 'history_status.partner_id = :id_partner and history_status.deleted_at is NULL', - { - id_partner: user.partner.id, - }, - ) - // .where(`history_status.partner_id = :id_partner`, { - // partner: user.partner.id, - // }) - .where(`history_status.status = 'ACTIVE'`, { - status: 'ACTIVE', - }) - .andWhere('supplier.status = TRUE', { - status: true - }) - .select(['product.id']) - .addSelect([ - 'product.name', - 'product.code', - 'product.type', - 'product.supplier_id', - 'sub_categories.name', - 'current_price.price as price', - ]) - .addSelect('history_status.status', 'status') .distinct(); // .addSelect( // '(current_price.price + current_price.mark_up_price) as price', @@ -538,6 +472,7 @@ export class ProductService { // id: subCategories, // }); // } + if (subCategories && filterSubCategories.length > 0) { baseQuery .where('product.sub_categories_id IN (:...subCategoryId)', { @@ -568,6 +503,10 @@ export class ProductService { dataa.price = actualPrice; + if (user.username != 'admin') { + dataa.remove('markup_price'); + } + newData.push({ ...dataa, }); From 8e9295a806f8fee6f88a95616525899f0008eef3 Mon Sep 17 00:00:00 2001 From: Muhammad Fadli Date: Fri, 28 Apr 2023 19:58:47 +0700 Subject: [PATCH 3/3] - fix get product partner hide markup price --- src/product/product.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 1ca6398..ebbcfcc 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -504,7 +504,7 @@ export class ProductService { dataa.price = actualPrice; if (user.username != 'admin') { - dataa.remove('markup_price'); + delete dataa.markup_price; } newData.push({