Merge branch 'development' into 'devops-staging'
fix: upload product See merge request empatnusabangsa/ppob/ppob-backend!63
This commit is contained in:
commit
09c2b93741
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user