identity-admin 1.28.30 → 1.28.31
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.
- package/lib/controllers/DashboardController.d.ts +1 -1
- package/lib/controllers/DashboardController.js +17 -9
- package/lib/helpers/PopulationHelper.d.ts +2 -1
- package/lib/helpers/PopulationHelper.js +10 -1
- package/lib/helpers/ReportsGenerator.d.ts +3 -0
- package/lib/helpers/ReportsGenerator.js +36 -0
- package/lib/repositories/Repository.d.ts +1 -0
- package/lib/repositories/Repository.js +4 -0
- package/lib/types/IResourceFile.d.ts +5 -0
- package/package.json +1 -1
|
@@ -36,7 +36,7 @@ export default class DashboardController {
|
|
|
36
36
|
index(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
37
37
|
create(req: IRequest, res: Response): Promise<void>;
|
|
38
38
|
update(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
39
|
-
report(req: IRequest, res: Response): Promise<void
|
|
39
|
+
report(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
40
40
|
show(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
41
41
|
deleteAll(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
42
42
|
delete(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
@@ -479,21 +479,27 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
479
479
|
if (crudOperations && crudOperations.index && crudOperations.index.before) {
|
|
480
480
|
filter = yield crudOperations.index.before(req, filter, currentUser);
|
|
481
481
|
}
|
|
482
|
+
const fields = ReportsGenerator_1.default.parseFields(req.query.fields);
|
|
483
|
+
if (fields.length === 0) {
|
|
484
|
+
return ResponseUtils_1.default.send(res, 400, 'fields query parameter is required');
|
|
485
|
+
}
|
|
486
|
+
const select = ReportsGenerator_1.default.buildSelect(fields);
|
|
487
|
+
const columnFieldKeys = ReportsGenerator_1.default.getColumnFieldKeys(fields);
|
|
482
488
|
var records = [];
|
|
483
|
-
const populatedString = modifiedResource.properties.populatedString
|
|
484
|
-
|
|
489
|
+
const populatedString = modifiedResource.properties.populatedString
|
|
490
|
+
.split(' ')
|
|
491
|
+
.filter((field) => columnFieldKeys.some((key) => field === key || field.startsWith(key + '.')))
|
|
492
|
+
.join(' ');
|
|
493
|
+
const populationHelper = new PopulationHelper_1.PopulationHelper(resource, PopulationHelper_1.PopulationType.REPORT, populatedString);
|
|
485
494
|
const modifiedPopulatedObject = yield populationHelper.get();
|
|
486
495
|
records = yield repository.findMany({
|
|
487
496
|
sort: sortQuery,
|
|
488
497
|
filter,
|
|
489
498
|
populate: modifiedPopulatedObject,
|
|
499
|
+
select,
|
|
500
|
+
lean: true,
|
|
490
501
|
});
|
|
491
|
-
var documents =
|
|
492
|
-
for (var i = 0; i < records.length; i++) {
|
|
493
|
-
const record = records[i];
|
|
494
|
-
const recordFlatten = record.toObject();
|
|
495
|
-
documents.push(recordFlatten);
|
|
496
|
-
}
|
|
502
|
+
var documents = records;
|
|
497
503
|
if (crudOperations && crudOperations.index && crudOperations.index.after) {
|
|
498
504
|
try {
|
|
499
505
|
documents = yield crudOperations.index.after(req, documents, currentUser);
|
|
@@ -502,7 +508,6 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
502
508
|
documents = yield crudOperations.index.after(req, records, currentUser);
|
|
503
509
|
}
|
|
504
510
|
}
|
|
505
|
-
const fields = req.query.fields.map((v) => JSON.parse(v));
|
|
506
511
|
const fileType = req.query.fileType;
|
|
507
512
|
if (fileType === 'xlsx') {
|
|
508
513
|
const buffer = ReportsGenerator_1.default.CreateXlsxFile(fields, documents, modelName, language, resource);
|
|
@@ -522,6 +527,9 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
522
527
|
});
|
|
523
528
|
res.end(buffer);
|
|
524
529
|
}
|
|
530
|
+
if (!fileType) {
|
|
531
|
+
return ResponseUtils_1.default.send(res, 400, 'fileType query parameter is required');
|
|
532
|
+
}
|
|
525
533
|
});
|
|
526
534
|
}
|
|
527
535
|
show(req, res) {
|
|
@@ -14,6 +14,7 @@ var PopulationType;
|
|
|
14
14
|
(function (PopulationType) {
|
|
15
15
|
PopulationType["LIST"] = "LIST";
|
|
16
16
|
PopulationType["SHOW"] = "SHOW";
|
|
17
|
+
PopulationType["REPORT"] = "REPORT";
|
|
17
18
|
})(PopulationType = exports.PopulationType || (exports.PopulationType = {}));
|
|
18
19
|
class PopulationHelper {
|
|
19
20
|
constructor(resource, populationType, populatedString) {
|
|
@@ -27,7 +28,7 @@ class PopulationHelper {
|
|
|
27
28
|
if (!populate) {
|
|
28
29
|
return this.populatedString;
|
|
29
30
|
}
|
|
30
|
-
if (!populate.all && !populate.list && !populate.show) {
|
|
31
|
+
if (!populate.all && !populate.list && !populate.show && !populate.report) {
|
|
31
32
|
return this.populatedString;
|
|
32
33
|
}
|
|
33
34
|
if (populate.all) {
|
|
@@ -38,6 +39,14 @@ class PopulationHelper {
|
|
|
38
39
|
return yield populate.list(this.populatedString);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
42
|
+
else if (this.populationType === PopulationType.REPORT) {
|
|
43
|
+
if (populate.report) {
|
|
44
|
+
return yield populate.report(this.populatedString);
|
|
45
|
+
}
|
|
46
|
+
if (populate.list) {
|
|
47
|
+
return yield populate.list(this.populatedString);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
41
50
|
else {
|
|
42
51
|
if (populate.show) {
|
|
43
52
|
return yield populate.show(this.populatedString);
|
|
@@ -22,5 +22,8 @@ export default class ReportsGenerator {
|
|
|
22
22
|
static getRows(columns: Columns[], data: any[], language: Languages, resource: IResourceFile): any[][];
|
|
23
23
|
static getFieldValue(field: Columns, row: any, language: Languages, resource: IResourceFile): any;
|
|
24
24
|
static checkLocalizedStringExistence(columns: Columns[]): boolean;
|
|
25
|
+
static parseFields(queryFields: any): Columns[];
|
|
26
|
+
static buildSelect(fields: Columns[]): Record<string, number>;
|
|
27
|
+
static getColumnFieldKeys(fields: Columns[]): string[];
|
|
25
28
|
static getReferenceValueByTitleType(rowValue: any, language: Languages, titleType?: FieldTypes): any;
|
|
26
29
|
}
|
|
@@ -132,6 +132,42 @@ class ReportsGenerator {
|
|
|
132
132
|
static checkLocalizedStringExistence(columns) {
|
|
133
133
|
return columns.some((column) => column.type === helpers_1.FieldTypes.LOCALIZEDSTRING);
|
|
134
134
|
}
|
|
135
|
+
static parseFields(queryFields) {
|
|
136
|
+
if (!queryFields)
|
|
137
|
+
return [];
|
|
138
|
+
if (Array.isArray(queryFields)) {
|
|
139
|
+
return queryFields.map((v) => (typeof v === 'string' ? JSON.parse(v) : v));
|
|
140
|
+
}
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
static buildSelect(fields) {
|
|
144
|
+
const select = {};
|
|
145
|
+
fields.forEach((field) => {
|
|
146
|
+
const topField = field.value.split('.')[0];
|
|
147
|
+
select[topField] = 1;
|
|
148
|
+
if (field.titlePath) {
|
|
149
|
+
const topTitlePath = field.titlePath.split('.')[0];
|
|
150
|
+
select[topTitlePath] = 1;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return select;
|
|
154
|
+
}
|
|
155
|
+
static getColumnFieldKeys(fields) {
|
|
156
|
+
const keys = [];
|
|
157
|
+
fields.forEach((field) => {
|
|
158
|
+
const topField = field.value.split('.')[0];
|
|
159
|
+
if (!keys.includes(topField)) {
|
|
160
|
+
keys.push(topField);
|
|
161
|
+
}
|
|
162
|
+
if (field.titlePath) {
|
|
163
|
+
const topTitlePath = field.titlePath.split('.')[0];
|
|
164
|
+
if (!keys.includes(topTitlePath)) {
|
|
165
|
+
keys.push(topTitlePath);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return keys;
|
|
170
|
+
}
|
|
135
171
|
static getReferenceValueByTitleType(rowValue, language, titleType) {
|
|
136
172
|
if (!titleType)
|
|
137
173
|
return rowValue;
|
|
@@ -49,6 +49,7 @@ let Repository = Repository_1 = class Repository {
|
|
|
49
49
|
const limit = this.getLimit(queryOptions);
|
|
50
50
|
const skip = this.getSkip(queryOptions);
|
|
51
51
|
const populate = queryOptions.populate;
|
|
52
|
+
const lean = queryOptions.lean;
|
|
52
53
|
var query = this.model.find(filter);
|
|
53
54
|
if (select) {
|
|
54
55
|
query = query.select(select);
|
|
@@ -65,6 +66,9 @@ let Repository = Repository_1 = class Repository {
|
|
|
65
66
|
if (populate) {
|
|
66
67
|
query = query.populate(populate);
|
|
67
68
|
}
|
|
69
|
+
if (lean) {
|
|
70
|
+
query = query.lean();
|
|
71
|
+
}
|
|
68
72
|
return yield query;
|
|
69
73
|
});
|
|
70
74
|
}
|
|
@@ -36,6 +36,11 @@ interface IPopulate {
|
|
|
36
36
|
* This function is called for the get one endpoint either in show or form an access over the populated string
|
|
37
37
|
*/
|
|
38
38
|
show?: PopulateFunction;
|
|
39
|
+
/**
|
|
40
|
+
* This function is called for the report endpoint to have an access over the populated string.
|
|
41
|
+
* Falls back to populate.list if not defined.
|
|
42
|
+
*/
|
|
43
|
+
report?: PopulateFunction;
|
|
39
44
|
}
|
|
40
45
|
interface Action {
|
|
41
46
|
/**
|