diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/services/index.ts | 2 | ||||
-rw-r--r-- | src/services/spreadsheets.service.ts | 31 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/services/index.ts b/src/services/index.ts index cabfff3..dd1591c 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -2,11 +2,13 @@ import { Application } from '@feathersjs/express'; import Products from './products.service'; import Contractors from './contractors.service'; import Waybills from './waybills.service'; +import Spreadsheets from './spreadsheets.service'; export default (app: Application): void => { app.configure(Products); app.configure(Contractors); app.configure(Waybills); + app.configure(Spreadsheets); app.get('/ping', (req, res) => res.send('pong')); }; 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); +}; |