fix: update and create product by csv
This commit is contained in:
parent
36f343a306
commit
1bfd132a2e
|
@ -1,5 +1,5 @@
|
||||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
import { EntityNotFoundError, IsNull, Repository } from 'typeorm';
|
||||||
import { Product } from './entities/product.entity';
|
import { Product } from './entities/product.entity';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { CreateProductDto } from './dto/product/create-product.dto';
|
import { CreateProductDto } from './dto/product/create-product.dto';
|
||||||
|
@ -87,27 +87,37 @@ export class ProductService {
|
||||||
partner: partnerData.id,
|
partner: partnerData.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
dataHistoryPrice = await this.productHistoryPrice.findOne({
|
dataHistoryPrice = await this.productHistoryPrice.findOne({
|
||||||
product: productData,
|
product: productData,
|
||||||
|
partner: IsNull(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dataHistoryPrice) {
|
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);
|
||||||
|
|
||||||
|
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,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
let partnerData;
|
let partnerData;
|
||||||
if (it[6] != '-' && it[6] != '') {
|
if (it[6] != '-' && it[6] != '') {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user