blob: 437deccb06b70bd1dbf6086e14c5b6691aaff84b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
};
|