fix: upload product

This commit is contained in:
ilham 2021-12-23 20:18:29 +07:00
parent 15852b1ecb
commit ef1ef4d429
3 changed files with 13 additions and 3 deletions

View File

@ -3,4 +3,7 @@ import { IsNotEmpty, IsUUID } from 'class-validator';
export class UploadProductDto { export class UploadProductDto {
@IsNotEmpty() @IsNotEmpty()
fileName: string; fileName: string;
@IsNotEmpty()
supplierCode: string;
} }

View File

@ -72,7 +72,10 @@ export class ProductController {
@Post('upload-product') @Post('upload-product')
async createProductBaseOnCSV(@Body() uploadProductDto: UploadProductDto) { async createProductBaseOnCSV(@Body() uploadProductDto: UploadProductDto) {
await this.productService.processUploadCSV(uploadProductDto.fileName); await this.productService.processUploadCSV(
uploadProductDto.fileName,
uploadProductDto.supplierCode,
);
return { return {
data: 'Done', data: 'Done',
@ -104,7 +107,7 @@ export class ProductController {
@Get('test') @Get('test')
async test(@Request() req) { async test(@Request() req) {
const data = await this.productService.processUploadCSV(''); const data = await this.productService.processUploadCSV('','');
return { return {
data, data,

View File

@ -50,7 +50,9 @@ export class ProductService {
return this.productRepository.findOneOrFail(result.identifiers[0].id); 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); const data = await parsingFile(uploadFile);
data.shift(); data.shift();
await Promise.all( await Promise.all(
@ -67,6 +69,7 @@ export class ProductService {
const productData = await this.productRepository.findOne({ const productData = await this.productRepository.findOne({
code: it[0], code: it[0],
supplier: supplierData,
}); });
if (productData) { if (productData) {
//TODO : Handle Update Product //TODO : Handle Update Product
@ -109,6 +112,7 @@ export class ProductService {
code: it[0], code: it[0],
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE', status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
sub_categories: subCategories, sub_categories: subCategories,
supplier: supplierData,
}); });
await this.productHistoryPrice.insert({ await this.productHistoryPrice.insert({