summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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, () => {});
+ });
+ });
};