Merge branch 'master' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-production
This commit is contained in:
		| @@ -7,29 +7,53 @@ const irs_user = 'D10BD0'; | |||||||
| const irs_pass = '6251F3'; | const irs_pass = '6251F3'; | ||||||
|  |  | ||||||
| export const doTransaction = async ( | export const doTransaction = async ( | ||||||
|   productCode, |     productCode, | ||||||
|   destination, |     destination, | ||||||
|   idtrx, |     idtrx, | ||||||
|   supplier, |     supplier, | ||||||
|  |     authorization, | ||||||
|  |     typePaid, | ||||||
| ) => { | ) => { | ||||||
|   try { |   try { | ||||||
|     if(supplier.code == 'IRS'){ |     if (supplier.code == 'IRS') { | ||||||
|       const res = await axios.get( |       const res = await axios.get( | ||||||
|         `${irs_url}?id=${irs_id}&pin=${irs_pin}&user=${irs_user}&pass=${irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`, |           `${irs_url}?id=${irs_id}&pin=${irs_pin}&user=${irs_user}&pass=${irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`, | ||||||
|       ); |       ); | ||||||
|  |  | ||||||
|       return res.data; |       return res.data; | ||||||
|     } else if (supplier.code == 'NIRS') { |     } else if (supplier.code == 'NIRS') { | ||||||
|       const res = await axios.get( |       const res = await axios.get( | ||||||
|           `${supplier.url}?id=${supplier.irs_id}&pin=${supplier.irs_pin}&user=${supplier.irs_user}&pass=${supplier.irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`, |           `${supplier.url}?id=${supplier.irs_id}&pin=${supplier.irs_pin}&user=${supplier.irs_user}&pass=${supplier.irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`, | ||||||
|       ); |       ); | ||||||
|  |  | ||||||
|       return res.data; |       return res.data; | ||||||
|     } else { |     } else if (supplier.code == 'Hemat') { | ||||||
|       const res = await axios.get( |       if (authorization != "") { | ||||||
|         `${supplier.url}?memberID=${supplier.irs_id}&pin=${supplier.irs_pin}&password=${supplier.irs_pass}&product=${productCode}&dest=${destination}&counter=1&refID=${idtrx}`, |         console.log("initoken", authorization) | ||||||
|       ); |         const options = { | ||||||
|       return res.data; |           headers: {'Content-Type': 'application/json', | ||||||
|  |             'Authorization': 'Bearer ' + authorization} | ||||||
|  |         }; | ||||||
|  |         const data = { | ||||||
|  |           idtransaction: idtrx, | ||||||
|  |           destination: `${destination}`, | ||||||
|  |           code: `${productCode}`, | ||||||
|  |           type: `${typePaid}`, | ||||||
|  |         }; | ||||||
|  |         const res = await axios.post(`${supplier.url}/v1/transaction/request`, data, options); | ||||||
|  |  | ||||||
|  |         return res.data; | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     const res = await axios.get( | ||||||
|  |         `${supplier.url}?memberID=${supplier.irs_id}&pin=${supplier.irs_pin}&password=${supplier.irs_pass}&product=${productCode}&dest=${destination}&counter=1&refID=${idtrx}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|  |     return res.data; | ||||||
|  |     console.log('restranshemat', res) | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|  |     console.log('errtranshemat', err.response.data); | ||||||
|     throw err; |     throw err; | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								src/helper/sihemat-authorization.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/helper/sihemat-authorization.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | import axios from 'axios'; | ||||||
|  |  | ||||||
|  | export const doAuthorizeHemat = async (user, pass, supplier) => { | ||||||
|  |     try { | ||||||
|  |         const data = { | ||||||
|  |             username: `${user}`, | ||||||
|  |             password: `${pass}`, | ||||||
|  |         }; | ||||||
|  |         const res = await axios.post(`${supplier.url}/authenticate`, data); | ||||||
|  |  | ||||||
|  |         return res.data; | ||||||
|  |     } catch (err) { | ||||||
|  |         console.log('errauthhemat', err) | ||||||
|  |         throw err; | ||||||
|  |     } | ||||||
|  | }; | ||||||
| @@ -17,21 +17,21 @@ import { ProductHistoryStatus } from './entities/product-history-status.entity'; | |||||||
|  |  | ||||||
| export class ProductService { | export class ProductService { | ||||||
|   constructor( |   constructor( | ||||||
|     @InjectRepository(Product) |       @InjectRepository(Product) | ||||||
|     private productRepository: Repository<Product>, |       private productRepository: Repository<Product>, | ||||||
|     @InjectRepository(ProductHistoryPrice) |       @InjectRepository(ProductHistoryPrice) | ||||||
|     private productHistoryPrice: Repository<ProductHistoryPrice>, |       private productHistoryPrice: Repository<ProductHistoryPrice>, | ||||||
|     @InjectRepository(ProductHistoryStatus) |       @InjectRepository(ProductHistoryStatus) | ||||||
|     private productHistoryStatus: Repository<ProductHistoryStatus>, |       private productHistoryStatus: Repository<ProductHistoryStatus>, | ||||||
|     private productSubCategoriesService: ProductSubCategoriesService, |       private productSubCategoriesService: ProductSubCategoriesService, | ||||||
|     private usersService: UsersService, |       private usersService: UsersService, | ||||||
|     private supplierService: SupplierService, |       private supplierService: SupplierService, | ||||||
|     private partnerService: PartnerService, |       private partnerService: PartnerService, | ||||||
|   ) {} |   ) {} | ||||||
|  |  | ||||||
|   async create(createProductDto: CreateProductDto) { |   async create(createProductDto: CreateProductDto) { | ||||||
|     const subCategories = await this.productSubCategoriesService.findOne( |     const subCategories = await this.productSubCategoriesService.findOne( | ||||||
|       createProductDto.subCategoriesId, |         createProductDto.subCategoriesId, | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     const result = await this.productRepository.insert({ |     const result = await this.productRepository.insert({ | ||||||
| @@ -66,7 +66,7 @@ export class ProductService { | |||||||
|       let productStatusPartner; |       let productStatusPartner; | ||||||
|  |  | ||||||
|       const subCategories = |       const subCategories = | ||||||
|         await this.productSubCategoriesService.findOneForCSVParser(it[2]); |           await this.productSubCategoriesService.findOneForCSVParser(it[2]); | ||||||
|  |  | ||||||
|       if (!subCategories) { |       if (!subCategories) { | ||||||
|         return; |         return; | ||||||
| @@ -193,10 +193,10 @@ export class ProductService { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   async findAll( |   async findAll( | ||||||
|     page: number, |       page: number, | ||||||
|     supplier: string, |       supplier: string, | ||||||
|     subCategories: string, |       subCategories: string, | ||||||
|     pageSize?: number, |       pageSize?: number, | ||||||
|   ) { |   ) { | ||||||
|     let filterSupplier, filterSubCategories; |     let filterSupplier, filterSubCategories; | ||||||
|  |  | ||||||
| @@ -213,40 +213,40 @@ export class ProductService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     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('sub_categories.category', 'category') |         .leftJoin('sub_categories.category', 'category') | ||||||
|       .leftJoin('product.supplier', 'supplier') |         .leftJoin('product.supplier', 'supplier') | ||||||
|       .where('supplier.status = :status', { status: true }) |         .where('supplier.status = :status', { status: true }) | ||||||
|       .innerJoinAndMapOne( |         .innerJoinAndMapOne( | ||||||
|         'product.currentPrice', |             'product.currentPrice', | ||||||
|         'product.priceHistory', |             'product.priceHistory', | ||||||
|         'current_price', |             'current_price', | ||||||
|         'current_price.end_date is NULL', |             'current_price.end_date is NULL', | ||||||
|       ) |         ) | ||||||
|       .innerJoinAndMapOne( |         .innerJoinAndMapOne( | ||||||
|         'product.currentStatus', |             'product.currentStatus', | ||||||
|         'product.statusHistory', |             'product.statusHistory', | ||||||
|         'history_status', |             'history_status', | ||||||
|         'history_status.deleted_at is NULL', |             'history_status.deleted_at is NULL', | ||||||
|       ) |         ) | ||||||
|       .select(['product.id']) |         .select(['product.id']) | ||||||
|       .addSelect([ |         .addSelect([ | ||||||
|         'product.name', |           'product.name', | ||||||
|         'product.code', |           'product.code', | ||||||
|         'sub_categories.name', |           'sub_categories.name', | ||||||
|         'supplier.name', |           'supplier.name', | ||||||
|         'category.name', |           'category.name', | ||||||
|       ]) |         ]) | ||||||
|       .addSelect('history_status.status', 'status') |         .addSelect('history_status.status', 'status') | ||||||
|       .addSelect('current_price.price', 'price') |         .addSelect('current_price.price', 'price') | ||||||
|       .addSelect('current_price.partner_fee', 'partner_fee') |         .addSelect('current_price.partner_fee', 'partner_fee') | ||||||
|       .addSelect('current_price.admin_price', 'admin_price') |         .addSelect('current_price.admin_price', 'admin_price') | ||||||
|       .addSelect( |         .addSelect( | ||||||
|         '(current_price.price + current_price.mark_up_price) as mark_up_price', |             '(current_price.price + current_price.mark_up_price) as mark_up_price', | ||||||
|       ) |         ) | ||||||
|       .orderBy('product.code') |         .orderBy('product.code') | ||||||
|       .distinct(); |         .distinct(); | ||||||
|  |  | ||||||
|     if (subCategories && filterSubCategories.length > 0) { |     if (subCategories && filterSubCategories.length > 0) { | ||||||
|       baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', { |       baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', { | ||||||
| @@ -261,9 +261,9 @@ export class ProductService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     const data = await baseQuery |     const data = await baseQuery | ||||||
|       .offset(page * (pageSize || 10)) |         .offset(page * (pageSize || 10)) | ||||||
|       .limit(pageSize || 10) |         .limit(pageSize || 10) | ||||||
|       .getRawMany(); |         .getRawMany(); | ||||||
|  |  | ||||||
|     const totalData = await baseQuery.getCount(); |     const totalData = await baseQuery.getCount(); | ||||||
|  |  | ||||||
| @@ -275,26 +275,26 @@ export class ProductService { | |||||||
|  |  | ||||||
|   async findAllByCategories(page, subCategories, supplier) { |   async findAllByCategories(page, subCategories, supplier) { | ||||||
|     const baseQuery = this.productRepository |     const baseQuery = this.productRepository | ||||||
|       .createQueryBuilder('product') |         .createQueryBuilder('product') | ||||||
|       .leftJoin('product.sub_categories', 'sub_categories') |         .leftJoin('product.sub_categories', 'sub_categories') | ||||||
|       .where( |         .where( | ||||||
|         'sub_categories.category_id = :id and product.supplier_id = :supplier_id', |             'sub_categories.category_id = :id and product.supplier_id = :supplier_id', | ||||||
|         { |             { | ||||||
|           id: subCategories, |               id: subCategories, | ||||||
|           supplier_id: supplier, |               supplier_id: supplier, | ||||||
|         }, |             }, | ||||||
|       ) |         ) | ||||||
|       .leftJoinAndMapOne( |         .leftJoinAndMapOne( | ||||||
|         'product.currentPrice', |             'product.currentPrice', | ||||||
|         'product.priceHistory', |             'product.priceHistory', | ||||||
|         'current_price', |             'current_price', | ||||||
|         'current_price.partner_id is null', |             'current_price.partner_id is null', | ||||||
|       ); |         ); | ||||||
|  |  | ||||||
|     const data = await baseQuery |     const data = await baseQuery | ||||||
|       .skip(page * 10) |         .skip(page * 10) | ||||||
|       .take(10) |         .take(10) | ||||||
|       .getMany(); |         .getMany(); | ||||||
|  |  | ||||||
|     const totalData = await baseQuery.getCount(); |     const totalData = await baseQuery.getCount(); | ||||||
|  |  | ||||||
| @@ -312,18 +312,18 @@ export class ProductService { | |||||||
|     console.log(supplier, 'asldklaksd') |     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.supplier', 'supplier') | ||||||
|  |  | ||||||
|         // .leftJoin('product.statusHistory', 'status_history') |         // .leftJoin('product.statusHistory', 'status_history') | ||||||
|  |  | ||||||
|       .leftJoinAndMapOne( |         .leftJoinAndMapOne( | ||||||
|         'product.currentPrice', |             'product.currentPrice', | ||||||
|         'product.priceHistory', |             'product.priceHistory', | ||||||
|         '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', | ||||||
|       ) |         ) | ||||||
|         .innerJoinAndMapOne( |         .innerJoinAndMapOne( | ||||||
|             'product.currentStatus', |             'product.currentStatus', | ||||||
|             'product.statusHistory', |             'product.statusHistory', | ||||||
| @@ -333,12 +333,12 @@ export class ProductService { | |||||||
|               status: 'ACTIVE', |               status: 'ACTIVE', | ||||||
|             }, |             }, | ||||||
|         ) |         ) | ||||||
|       // .where( |         // .where( | ||||||
|       //   `product.supplier_id = :supplier_id`, |         //   `product.supplier_id = :supplier_id`, | ||||||
|       //   { |         //   { | ||||||
|       //     supplier_id: supplier, |         //     supplier_id: supplier, | ||||||
|       //   }, |         //   }, | ||||||
|       // ) |         // ) | ||||||
|         .where( |         .where( | ||||||
|             `history_status.partner_id is NULL`, |             `history_status.partner_id is NULL`, | ||||||
|             { |             { | ||||||
| @@ -351,14 +351,14 @@ export class ProductService { | |||||||
|               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('product.supplier_id', 'supplier') | ||||||
|         .addSelect('supplier.status', 'status') |         .addSelect('supplier.status', 'status') | ||||||
|         .addSelect('history_status.partner_id', 'partner') |         .addSelect('history_status.partner_id', 'partner') | ||||||
|         .orderBy('price', 'ASC') |         .orderBy('price', 'ASC') | ||||||
|       .distinct(); |         .distinct(); | ||||||
|  |  | ||||||
|     if (subCategories != 'null' && subCategories) { |     if (subCategories != 'null' && subCategories) { | ||||||
|       baseQuery.andWhere('product.sub_categories_id = :id', { |       baseQuery.andWhere('product.sub_categories_id = :id', { | ||||||
| @@ -367,9 +367,9 @@ export class ProductService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     const data = await baseQuery |     const data = await baseQuery | ||||||
|       .offset(page * 1000) |         .offset(page * 1000) | ||||||
|       .limit(1000) |         .limit(1000) | ||||||
|       .getRawMany(); |         .getRawMany(); | ||||||
|  |  | ||||||
|     const totalData = await baseQuery.getCount(); |     const totalData = await baseQuery.getCount(); | ||||||
|  |  | ||||||
| @@ -380,10 +380,10 @@ export class ProductService { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   async findAllForPartner( |   async findAllForPartner( | ||||||
|     page: number, |       page: number, | ||||||
|     pageSize: number, |       pageSize: number, | ||||||
|     subCategories: string, |       subCategories: string, | ||||||
|     username: string, |       username: string, | ||||||
|   ) { |   ) { | ||||||
|     let filterSubCategories; |     let filterSubCategories; | ||||||
|     const user = await this.usersService.findOneByUsername(username); |     const user = await this.usersService.findOneByUsername(username); | ||||||
| @@ -396,68 +396,68 @@ export class ProductService { | |||||||
|  |  | ||||||
|     if (user.partner === null) { |     if (user.partner === null) { | ||||||
|       throw new HttpException( |       throw new HttpException( | ||||||
|         { |           { | ||||||
|           statusCode: HttpStatus.NOT_FOUND, |             statusCode: HttpStatus.NOT_FOUND, | ||||||
|           error: 'Partner id not found', |             error: 'Partner id not found', | ||||||
|         }, |           }, | ||||||
|         HttpStatus.NOT_FOUND, |           HttpStatus.NOT_FOUND, | ||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     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') | ||||||
|         .leftJoin('product.supplier', 'supplier') |         .leftJoin('product.supplier', 'supplier') | ||||||
|         // .leftJoinAndSelect( |         // .leftJoinAndSelect( | ||||||
|       //   'product.supplier', |         //   'product.supplier', | ||||||
|       //   'supplier', |         //   'supplier', | ||||||
|       //   'supplier.status = true', |         //   'supplier.status = true', | ||||||
|       //     { |         //     { | ||||||
|       //       status: true |         //       status: true | ||||||
|       //     } |         //     } | ||||||
|       // |         // | ||||||
|       // ) |         // ) | ||||||
|       .innerJoinAndMapOne( |         .innerJoinAndMapOne( | ||||||
|         'product.currentPrice', |             'product.currentPrice', | ||||||
|         'product.priceHistory', |             'product.priceHistory', | ||||||
|         'current_price', |             'current_price', | ||||||
|         'current_price.partner_id = :id_partner and current_price.end_date is NULL', |             'current_price.partner_id = :id_partner and current_price.end_date is NULL', | ||||||
|         { |             { | ||||||
|           id_partner: user.partner.id, |               id_partner: user.partner.id, | ||||||
|         }, |             }, | ||||||
|       ) |         ) | ||||||
|       .innerJoinAndMapOne( |         .innerJoinAndMapOne( | ||||||
|         'product.currentStatus', |             'product.currentStatus', | ||||||
|         'product.statusHistory', |             'product.statusHistory', | ||||||
|         'history_status', |             'history_status', | ||||||
|         'history_status.partner_id = :id_partner and history_status.deleted_at is NULL', |             'history_status.partner_id = :id_partner and history_status.deleted_at is NULL', | ||||||
|         { |             { | ||||||
|           id_partner: user.partner.id, |               id_partner: user.partner.id, | ||||||
|         }, |             }, | ||||||
|       ) |         ) | ||||||
|       // .where(`history_status.partner_id = :id_partner`, { |         // .where(`history_status.partner_id = :id_partner`, { | ||||||
|       //   partner: user.partner.id, |         //   partner: user.partner.id, | ||||||
|       // }) |         // }) | ||||||
|       .where(`history_status.status = 'ACTIVE'`, { |         .where(`history_status.status = 'ACTIVE'`, { | ||||||
|         status: 'ACTIVE', |           status: 'ACTIVE', | ||||||
|       }) |         }) | ||||||
|         .andWhere('supplier.status = TRUE', { |         .andWhere('supplier.status = TRUE', { | ||||||
|           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', |           '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', | ||||||
|         'current_price.partner_fee as partner_fee', |           'current_price.partner_fee as partner_fee', | ||||||
|         'current_price.price as price', |           'current_price.price as price', | ||||||
|       ]) |         ]) | ||||||
|       .addSelect('history_status.status', 'status') |         .addSelect('history_status.status', 'status') | ||||||
|       .distinct(); |         .distinct(); | ||||||
|     // .addSelect( |     // .addSelect( | ||||||
|     //   '(current_price.price + current_price.mark_up_price) as price', |     //   '(current_price.price + current_price.mark_up_price) as price', | ||||||
|     // ); |     // ); | ||||||
| @@ -474,18 +474,18 @@ export class ProductService { | |||||||
|  |  | ||||||
|     if (subCategories && filterSubCategories.length > 0) { |     if (subCategories && filterSubCategories.length > 0) { | ||||||
|       baseQuery |       baseQuery | ||||||
|         .where('product.sub_categories_id IN (:...subCategoryId)', { |           .where('product.sub_categories_id IN (:...subCategoryId)', { | ||||||
|           subCategoryId: filterSubCategories, |             subCategoryId: filterSubCategories, | ||||||
|         }) |           }) | ||||||
|         .andWhere(`history_status.status = 'ACTIVE'`); |           .andWhere(`history_status.status = 'ACTIVE'`); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const newData = []; |     const newData = []; | ||||||
|  |  | ||||||
|     const data = await baseQuery |     const data = await baseQuery | ||||||
|       .offset(page * pageSize) |         .offset(page * pageSize) | ||||||
|       .limit(pageSize) |         .limit(pageSize) | ||||||
|       .getRawMany(); |         .getRawMany(); | ||||||
|  |  | ||||||
|     data.map((dataa) => { |     data.map((dataa) => { | ||||||
|       let actualPrice = 0; |       let actualPrice = 0; | ||||||
| @@ -496,8 +496,8 @@ export class ProductService { | |||||||
|  |  | ||||||
|       if (dataa.product_type === 'postpaid') { |       if (dataa.product_type === 'postpaid') { | ||||||
|         actualPrice = |         actualPrice = | ||||||
|           Number(dataa['admin_price']) - |             Number(dataa['admin_price']) - | ||||||
|           (Number(dataa['partner_fee']) + Number(dataa['markup_price'])); |             (Number(dataa['partner_fee']) + Number(dataa['markup_price'])); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       dataa.price = actualPrice; |       dataa.price = actualPrice; | ||||||
| @@ -515,22 +515,23 @@ export class ProductService { | |||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   async findOne(code: string, type: string) { |   async findOne(code: string, type: string, productId: string) { | ||||||
|     try { |     try { | ||||||
|       return await this.productRepository.findOneOrFail({ |       return await this.productRepository.findOneOrFail({ | ||||||
|         relations: ['supplier'], |         relations: ['supplier'], | ||||||
|         where: { |         where: { | ||||||
|           code: code, |           code: code, | ||||||
|  |           id: productId | ||||||
|         }, |         }, | ||||||
|       }); |       }); | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       if (e instanceof EntityNotFoundError) { |       if (e instanceof EntityNotFoundError) { | ||||||
|         throw new HttpException( |         throw new HttpException( | ||||||
|           { |             { | ||||||
|             statusCode: HttpStatus.NOT_FOUND, |               statusCode: HttpStatus.NOT_FOUND, | ||||||
|             error: 'Product not found', |               error: 'Product not found', | ||||||
|           }, |             }, | ||||||
|           HttpStatus.NOT_FOUND, |             HttpStatus.NOT_FOUND, | ||||||
|         ); |         ); | ||||||
|       } else { |       } else { | ||||||
|         throw e; |         throw e; | ||||||
| @@ -539,31 +540,31 @@ export class ProductService { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   async findOneActive( |   async findOneActive( | ||||||
|     code: string, |       code: string, | ||||||
|     type: string, |       type: string, | ||||||
|     productId: string |       productId: string | ||||||
|   ) { |   ) { | ||||||
|       try { |     try { | ||||||
|         return await this.productRepository.findOneOrFail({ |       return await this.productRepository.findOneOrFail({ | ||||||
|           relations: ['supplier'], |         relations: ['supplier'], | ||||||
|           where: { |         where: { | ||||||
|             code: code, |           code: code, | ||||||
|             id: productId |           id: productId | ||||||
|           }, |         }, | ||||||
|         }); |       }); | ||||||
|       } catch (e) { |     } catch (e) { | ||||||
|         if (e instanceof EntityNotFoundError) { |       if (e instanceof EntityNotFoundError) { | ||||||
|           throw new HttpException( |         throw new HttpException( | ||||||
|             { |             { | ||||||
|               statusCode: HttpStatus.NOT_FOUND, |               statusCode: HttpStatus.NOT_FOUND, | ||||||
|               error: 'Product not found', |               error: 'Product not found', | ||||||
|             }, |             }, | ||||||
|             HttpStatus.NOT_FOUND, |             HttpStatus.NOT_FOUND, | ||||||
|           ); |         ); | ||||||
|         } else { |       } else { | ||||||
|           throw e; |         throw e; | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -578,11 +579,11 @@ export class ProductService { | |||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       if (e instanceof EntityNotFoundError) { |       if (e instanceof EntityNotFoundError) { | ||||||
|         throw new HttpException( |         throw new HttpException( | ||||||
|           { |             { | ||||||
|             statusCode: HttpStatus.NOT_FOUND, |               statusCode: HttpStatus.NOT_FOUND, | ||||||
|             error: 'Product not found', |               error: 'Product not found', | ||||||
|           }, |             }, | ||||||
|           HttpStatus.NOT_FOUND, |             HttpStatus.NOT_FOUND, | ||||||
|         ); |         ); | ||||||
|       } else { |       } else { | ||||||
|         throw e; |         throw e; | ||||||
| @@ -596,11 +597,11 @@ export class ProductService { | |||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       if (e instanceof EntityNotFoundError) { |       if (e instanceof EntityNotFoundError) { | ||||||
|         throw new HttpException( |         throw new HttpException( | ||||||
|           { |             { | ||||||
|             statusCode: HttpStatus.NOT_FOUND, |               statusCode: HttpStatus.NOT_FOUND, | ||||||
|             error: 'Product not found', |               error: 'Product not found', | ||||||
|           }, |             }, | ||||||
|           HttpStatus.NOT_FOUND, |             HttpStatus.NOT_FOUND, | ||||||
|         ); |         ); | ||||||
|       } else { |       } else { | ||||||
|         throw e; |         throw e; | ||||||
| @@ -608,7 +609,7 @@ export class ProductService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     const subCategories = await this.productSubCategoriesService.findOne( |     const subCategories = await this.productSubCategoriesService.findOne( | ||||||
|       updateProductDto.subCategoriesId, |         updateProductDto.subCategoriesId, | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     const dataStatus = await this.productHistoryStatus.findOne({ |     const dataStatus = await this.productHistoryStatus.findOne({ | ||||||
| @@ -632,19 +633,19 @@ export class ProductService { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   async updatePrice( |   async updatePrice( | ||||||
|     code: string, |       code: string, | ||||||
|     updatePriceProductDto: UpdatePriceProductDto, |       updatePriceProductDto: UpdatePriceProductDto, | ||||||
|   ) { |   ) { | ||||||
|     const product = await this.findOne(code, updatePriceProductDto.productType); |     // const product = await this.findOne(code, updatePriceProductDto.productType); | ||||||
|  |  | ||||||
|     await this.productHistoryPrice.insert({ |     // await this.productHistoryPrice.insert({ | ||||||
|       product: product, |     //   product: product, | ||||||
|       type: updatePriceProductDto.type, |     //   type: updatePriceProductDto.type, | ||||||
|       price: updatePriceProductDto.price, |     //   price: updatePriceProductDto.price, | ||||||
|       mark_up_price: updatePriceProductDto.markUpPrice, |     //   mark_up_price: updatePriceProductDto.markUpPrice, | ||||||
|       startDate: updatePriceProductDto.startDate, |     //   startDate: updatePriceProductDto.startDate, | ||||||
|       endDate: updatePriceProductDto.endDate, |     //   endDate: updatePriceProductDto.endDate, | ||||||
|     }); |     // }); | ||||||
|  |  | ||||||
|     return true; |     return true; | ||||||
|   } |   } | ||||||
| @@ -655,11 +656,11 @@ export class ProductService { | |||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       if (e instanceof EntityNotFoundError) { |       if (e instanceof EntityNotFoundError) { | ||||||
|         throw new HttpException( |         throw new HttpException( | ||||||
|           { |             { | ||||||
|             statusCode: HttpStatus.NOT_FOUND, |               statusCode: HttpStatus.NOT_FOUND, | ||||||
|             error: 'Product not found', |               error: 'Product not found', | ||||||
|           }, |             }, | ||||||
|           HttpStatus.NOT_FOUND, |             HttpStatus.NOT_FOUND, | ||||||
|         ); |         ); | ||||||
|       } else { |       } else { | ||||||
|         throw e; |         throw e; | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user