summaryrefslogtreecommitdiff
path: root/src/services/spreadsheets.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/spreadsheets.service.ts')
-rw-r--r--src/services/spreadsheets.service.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/services/spreadsheets.service.ts b/src/services/spreadsheets.service.ts
new file mode 100644
index 0000000..437decc
--- /dev/null
+++ b/src/services/spreadsheets.service.ts
@@ -0,0 +1,31 @@
+import { Application } from '@feathersjs/express';
+import { ServiceMethods, Id } from '@feathersjs/feathers';
+import ExcelJS from 'exceljs';
+import { WaybillSchema } from '../models/waybill/waybill.schema';
+
+
+class Spreadsheets implements Partial<ServiceMethods<any>> {
+ app!: Application;
+
+ setup(app: Application) {
+ this.app = app;
+ }
+
+ async get(id: Id) {
+ const waybill: WaybillSchema = await this.app.service('waybills').get(id);
+ const workbook = new ExcelJS.Workbook();
+ const sheet = workbook.addWorksheet('Накладная');
+
+ waybill.records.forEach(record => {
+ sheet.addRow([record.productId, record.quantity, record.price]);
+ });
+
+ await workbook.xlsx.writeFile('./documents/waybill.xlsx');
+ return 'written!';
+ }
+}
+
+
+export default (app: Application): void => {
+ app.use('/spreadsheets', new Spreadsheets);
+};