fix: update and create product by csv

This commit is contained in:
ilham 2021-12-26 12:02:56 +07:00
parent 36f343a306
commit 1bfd132a2e

View File

@ -1,5 +1,5 @@
import { HttpException, HttpStatus } from '@nestjs/common';
import { EntityNotFoundError, Repository } from 'typeorm';
import { EntityNotFoundError, IsNull, Repository } from 'typeorm';
import { Product } from './entities/product.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { CreateProductDto } from './dto/product/create-product.dto';
@ -87,16 +87,25 @@ export class ProductService {
partner: partnerData.id,
},
});
} else {
dataHistoryPrice = await this.productHistoryPrice.findOne({
product: productData,
partner: IsNull(),
});
}
if (!dataHistoryPrice) {
return;
}
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);
@ -108,6 +117,7 @@ export class ProductService {
startDate: new Date(),
partner: it[6] != '-' ? partnerData : null,
});
}
} else {
let partnerData;
if (it[6] != '-' && it[6] != '') {