identity-admin 1.26.23 → 1.27.1

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.
@@ -124,7 +124,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
124
124
  return (_b = this.modelConfigurations) === null || _b === void 0 ? void 0 : _b.get(modelName);
125
125
  }
126
126
  const collection = mongoose_1.default.connection.db.collection('modelconfigurations');
127
- return yield collection.findOne({ modelName: modelName });
127
+ return (yield collection.findOne({ modelName: modelName }));
128
128
  });
129
129
  }
130
130
  index(req, res) {
@@ -287,7 +287,9 @@ let DashboardController = DashboardController_1 = class DashboardController {
287
287
  record = yield repository.save(recordParams);
288
288
  }
289
289
  if (!record.isValid() || !record.document) {
290
- return ResponseUtils_1.default.unprocessable(res, 'Invalid Data', record.getErrors());
290
+ const errors = record.getErrors();
291
+ const errorMessage = errors && errors.length > 0 ? errors[0].message : 'Invalid Data';
292
+ return ResponseUtils_1.default.unprocessable(res, errorMessage, record.getErrors());
291
293
  }
292
294
  if ((_g = resource.properties) === null || _g === void 0 ? void 0 : _g.enableLog) {
293
295
  const newRecord = yield repository.findById(record.getDocument()._id);
@@ -396,6 +398,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
396
398
  const scope = req.query.scope;
397
399
  const currentUser = req.user;
398
400
  const modelName = req.params.resource;
401
+ const language = req.headers.language ? req.headers.language : 'en';
399
402
  const filtersQuery = req.query.filters;
400
403
  const filters = filtersQuery ? filtersQuery.split('^^') : undefined;
401
404
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
@@ -460,7 +463,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
460
463
  const fields = req.query.fields.map((v) => JSON.parse(v));
461
464
  const fileType = req.query.fileType;
462
465
  if (fileType === 'xlsx') {
463
- const buffer = ReportsGenerator_1.default.CreateXlsxFile(fields, documents, modelName);
466
+ const buffer = ReportsGenerator_1.default.CreateXlsxFile(fields, documents, modelName, language);
464
467
  res.writeHead(200, {
465
468
  'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
466
469
  'Content-disposition': 'attachment;filename=' + `${modelName}.xlsx`,
@@ -469,7 +472,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
469
472
  res.end(buffer);
470
473
  }
471
474
  if (fileType === 'pdf') {
472
- const buffer = yield ReportsGenerator_1.default.CreatePdfFile(fields, documents, modelName);
475
+ const buffer = yield ReportsGenerator_1.default.CreatePdfFile(fields, documents, modelName, language);
473
476
  res.writeHead(200, {
474
477
  'Content-Type': 'application/pdf',
475
478
  'Content-disposition': 'attachment;filename=' + `${modelName}.pdf`,
@@ -692,7 +695,7 @@ __decorate([
692
695
  __param(1, (0, inversify_express_utils_1.response)())
693
696
  ], DashboardController.prototype, "validateRequest", null);
694
697
  __decorate([
695
- (0, inversify_express_utils_1.httpGet)("/"),
698
+ (0, inversify_express_utils_1.httpGet)('/'),
696
699
  __param(0, (0, inversify_express_utils_1.request)()),
697
700
  __param(1, (0, inversify_express_utils_1.response)())
698
701
  ], DashboardController.prototype, "index", null);
@@ -1,4 +1,5 @@
1
1
  import { IResourceFile } from '../types/IResourceFile';
2
+ import { Languages } from './ReportsGenerator';
2
3
  export default class LocalizedStringHelper {
3
4
  static mapLocalizableString(recordParams: any, resource: IResourceFile): any;
4
5
  private static getArrayOfLanguages;
@@ -6,4 +7,5 @@ export default class LocalizedStringHelper {
6
7
  static getFilterObject(searchBy: string, index: string, value: any): {
7
8
  [key: string]: any;
8
9
  };
10
+ static getLocalizedValue(document: any, field: string, language?: Languages): any;
9
11
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const helpers_1 = require("../types/helpers");
4
+ const ReportsGenerator_1 = require("./ReportsGenerator");
4
5
  class LocalizedStringHelper {
5
6
  static mapLocalizableString(recordParams, resource) {
6
7
  const modelObject = resource.properties.model;
@@ -53,5 +54,21 @@ class LocalizedStringHelper {
53
54
  filterObject[`${searchBy}.${index}.value`] = value;
54
55
  return filterObject;
55
56
  }
57
+ static getLocalizedValue(document, field, language) {
58
+ if (!language) {
59
+ language = ReportsGenerator_1.Languages.ENGLISH;
60
+ }
61
+ if (!document[field] || document[field].length === 0) {
62
+ return '';
63
+ }
64
+ switch (language) {
65
+ case ReportsGenerator_1.Languages.ENGLISH:
66
+ return document[field][0].value;
67
+ case ReportsGenerator_1.Languages.ARABIC:
68
+ return document[field].length >= 2 && document[field][1].value ? document[field][1].value : document[field][0].value;
69
+ default:
70
+ return document[field][0].value;
71
+ }
72
+ }
56
73
  }
57
74
  exports.default = LocalizedStringHelper;
@@ -14,9 +14,9 @@ export interface ILanguage {
14
14
  value?: string;
15
15
  }
16
16
  export default class ReportsGenerator {
17
- static CreateXlsxFile(columns: Columns[], data: any[], name: string): Buffer;
18
- static CreatePdfFile(columns: Columns[], data: any[], name: string): Promise<Buffer>;
19
- static getRows(columns: Columns[], data: any[]): any[][];
20
- static getFieldValue(field: Columns, row: any): any;
17
+ static CreateXlsxFile(columns: Columns[], data: any[], name: string, language: Languages): Buffer;
18
+ static CreatePdfFile(columns: Columns[], data: any[], name: string, language: Languages): Promise<Buffer>;
19
+ static getRows(columns: Columns[], data: any[], language: Languages): any[][];
20
+ static getFieldValue(field: Columns, row: any, language: Languages): any;
21
21
  static checkLocalizedStringExistence(columns: Columns[]): boolean;
22
22
  }
@@ -41,15 +41,16 @@ const lodash_1 = require("lodash");
41
41
  const helpers_1 = require("../types/helpers");
42
42
  const pdfjs_1 = __importDefault(require("pdfjs"));
43
43
  const fs = __importStar(require("fs"));
44
+ const LocalizedStringHelper_1 = __importDefault(require("./LocalizedStringHelper"));
44
45
  var Languages;
45
46
  (function (Languages) {
46
47
  Languages["ARABIC"] = "ar";
47
48
  Languages["ENGLISH"] = "en";
48
49
  })(Languages = exports.Languages || (exports.Languages = {}));
49
50
  class ReportsGenerator {
50
- static CreateXlsxFile(columns, data, name) {
51
+ static CreateXlsxFile(columns, data, name, language) {
51
52
  const header = columns.map((field) => field.label);
52
- const rows = this.getRows(columns, data);
53
+ const rows = this.getRows(columns, data, language);
53
54
  const sheets = [
54
55
  {
55
56
  name,
@@ -60,9 +61,9 @@ class ReportsGenerator {
60
61
  const buffer = node_xlsx_1.default.build(sheets);
61
62
  return buffer;
62
63
  }
63
- static CreatePdfFile(columns, data, name) {
64
+ static CreatePdfFile(columns, data, name, language) {
64
65
  return __awaiter(this, void 0, void 0, function* () {
65
- const rows = this.getRows(columns, data);
66
+ const rows = this.getRows(columns, data, language);
66
67
  const ArabicFont = new pdfjs_1.default.Font(fs.readFileSync(__dirname + '/../assets/Amiri-Regular.ttf'));
67
68
  const localizedStringIsExisted = this.checkLocalizedStringExistence(columns);
68
69
  const doc = new pdfjs_1.default.Document({
@@ -85,22 +86,17 @@ class ReportsGenerator {
85
86
  return yield doc.asBuffer();
86
87
  });
87
88
  }
88
- static getRows(columns, data) {
89
- const rows = data.map((row) => columns.map((field) => this.getFieldValue(field, row)));
89
+ static getRows(columns, data, language) {
90
+ const rows = data.map((row) => columns.map((field) => this.getFieldValue(field, row, language)));
90
91
  return rows;
91
92
  }
92
- static getFieldValue(field, row) {
93
+ static getFieldValue(field, row, language) {
93
94
  var _a, _b;
94
95
  switch (field.type) {
95
96
  case helpers_1.FieldTypes.OBJECTID:
96
97
  return (_b = (_a = (0, lodash_1.get)(row, field.value)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '';
97
98
  case helpers_1.FieldTypes.LOCALIZEDSTRING:
98
- const items = (0, lodash_1.get)(row, field.value);
99
- var formattedString = ``;
100
- items.forEach((item) => {
101
- formattedString += `${item.key} --> ${item.value}\n`;
102
- });
103
- return formattedString;
99
+ return LocalizedStringHelper_1.default.getLocalizedValue(row, field.value, language);
104
100
  default:
105
101
  return (0, lodash_1.get)(row, field.value);
106
102
  }
@@ -174,6 +174,9 @@ let Repository = Repository_1 = class Repository {
174
174
  };
175
175
  });
176
176
  }
177
+ else {
178
+ errors = [{ path: e.keyPattern, type: "", message: e.message }];
179
+ }
177
180
  }
178
181
  return new SaveResult_1.default(document, errors);
179
182
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.26.23",
3
+ "version": "1.27.1",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",