From c3c2aa55bf5b9e5c2d5ab21c608dc7b5cd738196 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 17 Mar 2021 12:24:40 +0300 Subject: feat: add initial Spreadhseets service --- src/services/spreadsheets.service.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/services/spreadsheets.service.ts (limited to 'src/services/spreadsheets.service.ts') 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> { + 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); +}; -- cgit v1.2.3