summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-18 01:26:41 +0300
committereug-vs <eug-vs@keemail.me>2021-03-18 01:26:41 +0300
commit2ea1cf63bac15552c754375a38909885c96c7eeb (patch)
tree2918c967620c45bc90171ff08252313de1506e2e
parent4db379b0f2c824baa19ef6c9a2f89e32e5cec591 (diff)
downloadcommercel-api-2ea1cf63bac15552c754375a38909885c96c7eeb.tar.gz
feat: remove file after download
-rw-r--r--src/services/spreadsheets.service.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/services/spreadsheets.service.ts b/src/services/spreadsheets.service.ts
index b33a653..b52d47e 100644
--- a/src/services/spreadsheets.service.ts
+++ b/src/services/spreadsheets.service.ts
@@ -2,6 +2,7 @@ import { Application } from '@feathersjs/express';
import { ServiceMethods, Id } from '@feathersjs/feathers';
import ExcelJS from 'exceljs';
import _ from 'lodash';
+import fs from 'fs';
import { WaybillSchema } from '../models/waybill/waybill.schema';
const duplicateRowWithMergedCells = (sheet: any, row: number, count: number) => {
@@ -57,13 +58,19 @@ class Spreadsheets implements Partial<ServiceMethods<any>> {
getCol('AP').value = record.price;
});
- await workbook.xlsx.writeFile('./documents/waybill.xlsx');
- console.log('written!');
- return 'written!';
+ const fileName = `./documents/${waybill._id}.xlsx`;
+ await workbook.xlsx.writeFile(fileName);
+ return fileName;
}
}
export default (app: Application): void => {
- app.use('/spreadsheets', new Spreadsheets);
+ app.use('/spreadsheets', new Spreadsheets, (req, res) => {
+ const fileName = res.data;
+ res.download(fileName, err => {
+ if (err) console.log(err);
+ fs.unlink(fileName, () => {});
+ });
+ });
};