Merge branch 'development' into 'devops-staging'

add: create product based on csv

See merge request empatnusabangsa/ppob/ppob-backend!58
This commit is contained in:
ilham dwi pratama 2021-12-23 05:50:04 +00:00
commit a59ce9ab22
4 changed files with 22 additions and 7 deletions

View File

@ -7,10 +7,7 @@ export async function parsingFile(dataFile) {
const results = []; const results = [];
const file = createReadStream( const file = createReadStream(
path.join( path.join(process.cwd(), `./files/${dataFile}`),
process.cwd(),
'./files/Template Upload Product - Sheet1-a532.csv',
),
); );
file file

View File

@ -0,0 +1,6 @@
import { IsNotEmpty, IsUUID } from 'class-validator';
export class UploadProductDto {
@IsNotEmpty()
fileName: string;
}

View File

@ -21,6 +21,7 @@ import { CreateSubCategoriesProductDto } from './dto/sub-categories/create-sub-c
import { CreateProductDto } from './dto/product/create-product.dto'; import { CreateProductDto } from './dto/product/create-product.dto';
import { UpdateProductDto } from './dto/product/update-product.dto'; import { UpdateProductDto } from './dto/product/update-product.dto';
import { ProductHistoryPriceService } from './history-price/history-price.service'; import { ProductHistoryPriceService } from './history-price/history-price.service';
import { UploadProductDto } from './dto/product/upload-product.dto';
@Controller({ @Controller({
path: 'product', path: 'product',
@ -69,6 +70,17 @@ export class ProductController {
}; };
} }
@Post('upload-product')
async createProductBaseOnCSV(@Body() uploadProductDto: UploadProductDto) {
await this.productService.processUploadCSV(uploadProductDto.fileName);
return {
data: 'Done',
statusCode: HttpStatus.CREATED,
message: 'success',
};
}
@Get('all') @Get('all')
async findAll( async findAll(
@Query('page') page: number, @Query('page') page: number,
@ -92,7 +104,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,8 +50,8 @@ export class ProductService {
return this.productRepository.findOneOrFail(result.identifiers[0].id); return this.productRepository.findOneOrFail(result.identifiers[0].id);
} }
async processUploadCSV() { async processUploadCSV(uploadFile: string) {
const data = await parsingFile(''); const data = await parsingFile(uploadFile);
data.shift(); data.shift();
await Promise.all( await Promise.all(
data.map(async (it) => { data.map(async (it) => {