summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-17 12:24:40 +0300
committereug-vs <eug-vs@keemail.me>2021-03-17 12:24:40 +0300
commitc3c2aa55bf5b9e5c2d5ab21c608dc7b5cd738196 (patch)
treede54ee4d36698dc0f9421036513e8a31f01637fb
parent2166f83b30ed7c025f51f185358417f49e60272f (diff)
downloadcommercel-api-c3c2aa55bf5b9e5c2d5ab21c608dc7b5cd738196.tar.gz
feat: add initial Spreadhseets service
-rw-r--r--src/services/index.ts2
-rw-r--r--src/services/spreadsheets.service.ts31
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);
+};