identity-admin 1.28.31 → 1.28.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -510,15 +510,13 @@ let DashboardController = DashboardController_1 = class DashboardController {
510
510
  }
511
511
  const fileType = req.query.fileType;
512
512
  if (fileType === 'xlsx') {
513
- const buffer = ReportsGenerator_1.default.CreateXlsxFile(fields, documents, modelName, language, resource);
514
513
  res.writeHead(200, {
515
514
  'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
516
- 'Content-disposition': 'attachment;filename=' + `${modelName}.xlsx`,
517
- 'Content-Length': buffer.length,
515
+ 'Content-disposition': `attachment;filename=${modelName}.xlsx`,
518
516
  });
519
- res.end(buffer);
517
+ yield ReportsGenerator_1.default.CreateXlsxStream(fields, documents, modelName, language, resource, res);
520
518
  }
521
- if (fileType === 'pdf') {
519
+ else if (fileType === 'pdf') {
522
520
  const buffer = yield ReportsGenerator_1.default.CreatePdfFile(fields, documents, modelName, language, resource);
523
521
  res.writeHead(200, {
524
522
  'Content-Type': 'application/pdf',
@@ -527,6 +525,22 @@ let DashboardController = DashboardController_1 = class DashboardController {
527
525
  });
528
526
  res.end(buffer);
529
527
  }
528
+ else if (fileType === 'csv') {
529
+ res.writeHead(200, {
530
+ 'Content-Type': 'text/csv; charset=utf-8',
531
+ 'Content-disposition': `attachment;filename=${modelName}.csv`,
532
+ });
533
+ res.write('\uFEFF');
534
+ res.write(fields.map((f) => `"${f.label}"`).join(',') + '\r\n');
535
+ documents.forEach((record) => {
536
+ const row = fields.map((f) => {
537
+ const val = ReportsGenerator_1.default.getFieldValue(f, record, language, resource);
538
+ return `"${String(val !== null && val !== void 0 ? val : '').replace(/"/g, '""')}"`;
539
+ }).join(',');
540
+ res.write(row + '\r\n');
541
+ });
542
+ res.end();
543
+ }
530
544
  if (!fileType) {
531
545
  return ResponseUtils_1.default.send(res, 400, 'fileType query parameter is required');
532
546
  }
@@ -17,6 +17,7 @@ export interface ILanguage {
17
17
  value?: string;
18
18
  }
19
19
  export default class ReportsGenerator {
20
+ static CreateXlsxStream(columns: Columns[], data: any[], name: string, language: Languages, resource: IResourceFile, stream: any): Promise<void>;
20
21
  static CreateXlsxFile(columns: Columns[], data: any[], name: string, language: Languages, resource: IResourceFile): Buffer;
21
22
  static CreatePdfFile(columns: Columns[], data: any[], name: string, language: Languages, resource: IResourceFile): Promise<Buffer>;
22
23
  static getRows(columns: Columns[], data: any[], language: Languages, resource: IResourceFile): any[][];
@@ -49,6 +49,24 @@ var Languages;
49
49
  Languages["ENGLISH"] = "en";
50
50
  })(Languages = exports.Languages || (exports.Languages = {}));
51
51
  class ReportsGenerator {
52
+ static CreateXlsxStream(columns, data, name, language, resource, stream) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const ExcelJS = require('exceljs');
55
+ const workbook = new ExcelJS.stream.xlsx.WorkbookWriter({
56
+ stream,
57
+ useStyles: false,
58
+ useSharedStrings: false,
59
+ });
60
+ const worksheet = workbook.addWorksheet(name);
61
+ worksheet.addRow(columns.map(f => f.label)).commit();
62
+ data.forEach((record) => {
63
+ const row = columns.map((f) => this.getFieldValue(f, record, language, resource));
64
+ worksheet.addRow(row).commit();
65
+ });
66
+ worksheet.commit();
67
+ yield workbook.commit();
68
+ });
69
+ }
52
70
  static CreateXlsxFile(columns, data, name, language, resource) {
53
71
  const header = columns.map((field) => field.label);
54
72
  const rows = this.getRows(columns, data, language, resource);
@@ -64,7 +82,6 @@ class ReportsGenerator {
64
82
  }
65
83
  static CreatePdfFile(columns, data, name, language, resource) {
66
84
  return __awaiter(this, void 0, void 0, function* () {
67
- const rows = this.getRows(columns, data, language, resource);
68
85
  const ArabicFont = new pdfjs_1.default.Font(fs.readFileSync(__dirname + '/../assets/Amiri-Regular.ttf'));
69
86
  const localizedStringIsExisted = this.checkLocalizedStringExistence(columns);
70
87
  const doc = new pdfjs_1.default.Document({
@@ -85,14 +102,17 @@ class ReportsGenerator {
85
102
  textAlign: 'center',
86
103
  alignment: 'center',
87
104
  }));
88
- rows.forEach((row) => {
105
+ data.forEach((record) => {
89
106
  const tableRow = table.row();
90
- row.map((cell) => tableRow.cell(`${cell !== null && cell !== void 0 ? cell : '---'}`, {
91
- textAlign: 'center',
92
- alignment: 'center',
93
- paddingBottom: 5,
94
- paddingTop: 5,
95
- }));
107
+ columns.forEach((field) => {
108
+ const value = this.getFieldValue(field, record, language, resource);
109
+ tableRow.cell(`${value !== null && value !== void 0 ? value : '---'}`, {
110
+ textAlign: 'center',
111
+ alignment: 'center',
112
+ paddingBottom: 5,
113
+ paddingTop: 5,
114
+ });
115
+ });
96
116
  });
97
117
  return yield doc.asBuffer();
98
118
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.28.31",
3
+ "version": "1.28.32",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",
@@ -50,6 +50,7 @@
50
50
  "connect-mongo": "^4.6.0",
51
51
  "cookie-parser": "^1.4.6",
52
52
  "deep-diff": "^1.0.2",
53
+ "exceljs": "^4.4.0",
53
54
  "express-session": "^1.17.3",
54
55
  "lodash": "^4.17.21",
55
56
  "memory-cache": "^0.2.0",