diff --git a/src/product/product.service.ts b/src/product/product.service.ts index e81bb71..a17f617 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -321,7 +321,7 @@ export class ProductService { ); } - const baseQuery = this.productRepository + const baseQuery = await this.productRepository .createQueryBuilder('product') .leftJoin('product.sub_categories', 'sub_categories') .leftJoinAndSelect( @@ -343,12 +343,16 @@ export class ProductService { .addSelect([ 'product.name', 'product.code', + 'product.type', 'sub_categories.name', 'current_price.admin_price as admin_price', + 'current_price.mark_up_price as markup_price', + 'current_price.partner_fee as partner_fee', + 'current_price.price as price', ]) - .addSelect( - '(current_price.price + current_price.mark_up_price) as price', - ); + // .addSelect( + // '(current_price.price + current_price.mark_up_price) as price', + // ); // if ( // subCategories != 'null' && @@ -360,17 +364,39 @@ export class ProductService { // }); // } - if (subCategories && filterSubCategories.length > 0) { + + if (subCategories && filterSubCategories.length > 0) { baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', { subCategoryId: filterSubCategories, }); } + const newData = [] + const data = await baseQuery .offset(page * pageSize) .limit(pageSize) .getRawMany(); + data.map((dataa) => { + let actualPrice = 0 + + if (dataa.product_type === 'prepaid') { + actualPrice = Number(dataa['price']) + Number(dataa['markup_price']) + } + + if (dataa.product_type === 'postpaid') { + actualPrice = Number(dataa['admin_price'])- (Number(dataa['partner_fee']) + Number(dataa['markup_price'])) + } + + dataa.price = actualPrice + + newData.push({ + ...dataa + }) + + }) + const totalData = await baseQuery.getCount(); return {