add: parser upload product
This commit is contained in:
28
src/helper/csv-parser.ts
Normal file
28
src/helper/csv-parser.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { createReadStream } from 'fs';
|
||||
import * as csvParser from 'csv-parser';
|
||||
import * as path from 'path';
|
||||
|
||||
export async function parsingFile(dataFile) {
|
||||
const parsingData: any = await new Promise((resolve, reject) => {
|
||||
const results = [];
|
||||
|
||||
const file = createReadStream(
|
||||
path.join(
|
||||
process.cwd(),
|
||||
'./files/Template Upload Product - Sheet1-a532.csv',
|
||||
),
|
||||
);
|
||||
|
||||
file
|
||||
.pipe(
|
||||
csvParser({
|
||||
headers: false,
|
||||
}),
|
||||
)
|
||||
.on('data', (data) => results.push(data))
|
||||
.on('end', () => {
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
return parsingData;
|
||||
}
|
||||
Reference in New Issue
Block a user