fix: upload product
This commit is contained in:
parent
15852b1ecb
commit
ef1ef4d429
|
@ -3,4 +3,7 @@ import { IsNotEmpty, IsUUID } from 'class-validator';
|
|||
export class UploadProductDto {
|
||||
@IsNotEmpty()
|
||||
fileName: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
supplierCode: string;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,10 @@ export class ProductController {
|
|||
|
||||
@Post('upload-product')
|
||||
async createProductBaseOnCSV(@Body() uploadProductDto: UploadProductDto) {
|
||||
await this.productService.processUploadCSV(uploadProductDto.fileName);
|
||||
await this.productService.processUploadCSV(
|
||||
uploadProductDto.fileName,
|
||||
uploadProductDto.supplierCode,
|
||||
);
|
||||
|
||||
return {
|
||||
data: 'Done',
|
||||
|
@ -104,7 +107,7 @@ export class ProductController {
|
|||
|
||||
@Get('test')
|
||||
async test(@Request() req) {
|
||||
const data = await this.productService.processUploadCSV('');
|
||||
const data = await this.productService.processUploadCSV('','');
|
||||
|
||||
return {
|
||||
data,
|
||||
|
|
|
@ -50,7 +50,9 @@ export class ProductService {
|
|||
return this.productRepository.findOneOrFail(result.identifiers[0].id);
|
||||
}
|
||||
|
||||
async processUploadCSV(uploadFile: string) {
|
||||
async processUploadCSV(uploadFile: string, supplierCode: string) {
|
||||
const supplierData = await this.supplierService.findByCode(supplierCode);
|
||||
|
||||
const data = await parsingFile(uploadFile);
|
||||
data.shift();
|
||||
await Promise.all(
|
||||
|
@ -67,6 +69,7 @@ export class ProductService {
|
|||
|
||||
const productData = await this.productRepository.findOne({
|
||||
code: it[0],
|
||||
supplier: supplierData,
|
||||
});
|
||||
if (productData) {
|
||||
//TODO : Handle Update Product
|
||||
|
@ -109,6 +112,7 @@ export class ProductService {
|
|||
code: it[0],
|
||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||
sub_categories: subCategories,
|
||||
supplier: supplierData,
|
||||
});
|
||||
|
||||
await this.productHistoryPrice.insert({
|
||||
|
|
Loading…
Reference in New Issue
Block a user