From f5b510d75b10580f7e2392a2949ec2efdb944cb7 Mon Sep 17 00:00:00 2001 From: ilham Date: Thu, 6 Jan 2022 23:13:38 +0700 Subject: [PATCH] fix: fix product upload --- src/product/product.service.ts | 35 +++++++++++--------------- src/transaction/transaction.service.ts | 2 +- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index db2aed9..0a29b68 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -84,38 +84,31 @@ export class ProductService { where: { product: productData.id, partner: partnerData.id, + endDate: IsNull(), }, }); - } else { dataHistoryPrice = await this.productHistoryPrice.findOne({ product: productData, partner: IsNull(), + endDate: IsNull(), }); } - if (!dataHistoryPrice) { - await this.productHistoryPrice.insert({ - product: productData, - mark_up_price: it[4], - price: it[3], - type: productType.NORMAL, - startDate: new Date(), - partner: it[6] != '-' ? partnerData : null, - }); - } else { - dataHistoryPrice.endDate = new Date(); - await this.productHistoryPrice.save(dataHistoryPrice); - - await this.productHistoryPrice.insert({ - product: productData, - mark_up_price: it[4], - price: it[3], - type: productType.NORMAL, - startDate: new Date(), - partner: it[6] != '-' ? partnerData : null, + if (dataHistoryPrice) { + await this.productHistoryPrice.update(dataHistoryPrice.id, { + endDate: new Date(), }); } + + await this.productHistoryPrice.insert({ + product: productData, + mark_up_price: it[4], + price: it[3], + type: productType.NORMAL, + startDate: new Date(), + partner: it[6] != '-' ? partnerData : null, + }); } else { let partnerData; if (it[6] != '-' && it[6] != '') { diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 6f1c04d..b1737ad 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -1062,7 +1062,7 @@ export class TransactionService { 'status', 'userData.name', ]) - .orderBy('transaction.created_at','DESC'); + .orderBy('transaction.created_at', 'DESC'); if (startDate && endDate) { baseQuery.andWhere(