identity-admin 1.24.1 → 1.24.3
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.
|
@@ -36,6 +36,7 @@ const FiltersHelper_1 = __importDefault(require("../helpers/FiltersHelper"));
|
|
|
36
36
|
const LocalizedStringHelper_1 = __importDefault(require("../helpers/LocalizedStringHelper"));
|
|
37
37
|
const ActionsGenerator_1 = __importDefault(require("../helpers/ActionsGenerator"));
|
|
38
38
|
const helpers_1 = require("../types/helpers");
|
|
39
|
+
const PopulationHelper_1 = require("../helpers/PopulationHelper");
|
|
39
40
|
let DashboardController = DashboardController_1 = class DashboardController {
|
|
40
41
|
constructor(resource, repository, resources, modelConfigurations) {
|
|
41
42
|
this.resource = resource;
|
|
@@ -157,7 +158,6 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
157
158
|
if (sortBy !== "_id") {
|
|
158
159
|
sortQuery._id = "asc";
|
|
159
160
|
}
|
|
160
|
-
const populate = req.query.populate;
|
|
161
161
|
var filter = {};
|
|
162
162
|
if (scope &&
|
|
163
163
|
resource.properties.filters &&
|
|
@@ -183,11 +183,14 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
183
183
|
}
|
|
184
184
|
var records = [];
|
|
185
185
|
var pageInfo = undefined;
|
|
186
|
+
const populatedString = modifiedResource.properties.populatedString;
|
|
187
|
+
const populationHelper = new PopulationHelper_1.PopulationHelper(resource, PopulationHelper_1.PopulationType.LIST, populatedString);
|
|
188
|
+
const modifiedPopulatedObject = yield populationHelper.get();
|
|
186
189
|
if (!req.query.page && !req.query.perPage) {
|
|
187
190
|
records = yield repository.findMany({
|
|
188
191
|
sort: sortQuery,
|
|
189
192
|
filter,
|
|
190
|
-
populate:
|
|
193
|
+
populate: modifiedPopulatedObject,
|
|
191
194
|
});
|
|
192
195
|
}
|
|
193
196
|
else {
|
|
@@ -195,7 +198,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
195
198
|
sort: sortQuery,
|
|
196
199
|
filter,
|
|
197
200
|
paginateParams: paginateParams,
|
|
198
|
-
populate:
|
|
201
|
+
populate: modifiedPopulatedObject,
|
|
199
202
|
});
|
|
200
203
|
records = page.records;
|
|
201
204
|
pageInfo = page.pageInfo;
|
|
@@ -364,11 +367,14 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
364
367
|
}
|
|
365
368
|
const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
|
|
366
369
|
const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser, undefined, this.modelConfigurations);
|
|
370
|
+
const populatedString = modifiedResource.properties.populatedString;
|
|
371
|
+
const populationHelper = new PopulationHelper_1.PopulationHelper(resource, PopulationHelper_1.PopulationType.SHOW, populatedString);
|
|
372
|
+
const modifiedPopulatedObject = yield populationHelper.get();
|
|
367
373
|
var record = yield repository.findOne({
|
|
368
374
|
filter: {
|
|
369
375
|
_id: recordId,
|
|
370
376
|
},
|
|
371
|
-
populate:
|
|
377
|
+
populate: modifiedPopulatedObject,
|
|
372
378
|
});
|
|
373
379
|
if (!record) {
|
|
374
380
|
return ResponseUtils_1.default.send(res, 404, "record not found");
|
|
@@ -489,11 +495,14 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
489
495
|
}
|
|
490
496
|
const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
|
|
491
497
|
const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser, undefined, this.modelConfigurations);
|
|
498
|
+
const populatedString = modifiedResource.properties.populatedString;
|
|
499
|
+
const populationHelper = new PopulationHelper_1.PopulationHelper(resource, PopulationHelper_1.PopulationType.SHOW, populatedString);
|
|
500
|
+
const modifiedPopulatedObject = yield populationHelper.get();
|
|
492
501
|
var record = yield repository.findOne({
|
|
493
502
|
filter: {
|
|
494
503
|
_id: recordId,
|
|
495
504
|
},
|
|
496
|
-
populate:
|
|
505
|
+
populate: modifiedPopulatedObject,
|
|
497
506
|
});
|
|
498
507
|
if (!record) {
|
|
499
508
|
return ResponseUtils_1.default.send(res, 404, "record not found");
|
|
@@ -502,20 +511,21 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
502
511
|
record = yield ResourceHelper_1.default.addExtraFields(modifiedResource.showProperties, modifiedResource.properties.model, record, StringUtils_1.default.lowerCaseFirstLetter(modifiedResource.properties.modelName), resource);
|
|
503
512
|
const sortBy = modifiedResource.properties
|
|
504
513
|
.defaultOrderBy;
|
|
514
|
+
const sort = modifiedResource.properties.defaultOrder;
|
|
505
515
|
const nextQuery = {};
|
|
506
516
|
const prevQuery = {};
|
|
507
|
-
const
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
517
|
+
const sortQuery = {};
|
|
518
|
+
const greaterThanQuery = { $gt: record[sortBy] };
|
|
519
|
+
const lessThanQuery = { $lt: record[sortBy] };
|
|
520
|
+
nextQuery[sortBy] = sort === 'asc' ? greaterThanQuery : lessThanQuery;
|
|
521
|
+
prevQuery[sortBy] = sort === 'asc' ? lessThanQuery : greaterThanQuery;
|
|
522
|
+
sortQuery[sortBy] = sort;
|
|
513
523
|
var neighbor;
|
|
514
524
|
if (neighborRecordType === helpers_1.NeighborTypes.NEXT) {
|
|
515
|
-
neighbor = yield (model === null || model === void 0 ? void 0 : model.findOne(nextQuery).sort(
|
|
525
|
+
neighbor = yield (model === null || model === void 0 ? void 0 : model.findOne(nextQuery).sort(sortQuery).limit(1));
|
|
516
526
|
}
|
|
517
527
|
else {
|
|
518
|
-
neighbor = yield (model === null || model === void 0 ? void 0 : model.findOne(prevQuery).sort(
|
|
528
|
+
neighbor = yield (model === null || model === void 0 ? void 0 : model.findOne(prevQuery).sort(sortQuery).limit(1));
|
|
519
529
|
}
|
|
520
530
|
const hasNeighbor = record && neighbor && neighbor._id ? true : false;
|
|
521
531
|
const neighborRecordId = hasNeighbor ? neighbor._id : undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IResourceFile } from "../types/IResourceFile";
|
|
2
|
+
export declare enum PopulationType {
|
|
3
|
+
LIST = "LIST",
|
|
4
|
+
SHOW = "SHOW"
|
|
5
|
+
}
|
|
6
|
+
export declare class PopulationHelper {
|
|
7
|
+
private resource;
|
|
8
|
+
private populatedString;
|
|
9
|
+
private populationType;
|
|
10
|
+
constructor(resource: IResourceFile, populationType: PopulationType, populatedString: any);
|
|
11
|
+
get(): Promise<any>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PopulationHelper = exports.PopulationType = void 0;
|
|
13
|
+
var PopulationType;
|
|
14
|
+
(function (PopulationType) {
|
|
15
|
+
PopulationType["LIST"] = "LIST";
|
|
16
|
+
PopulationType["SHOW"] = "SHOW";
|
|
17
|
+
})(PopulationType = exports.PopulationType || (exports.PopulationType = {}));
|
|
18
|
+
class PopulationHelper {
|
|
19
|
+
constructor(resource, populationType, populatedString) {
|
|
20
|
+
this.resource = resource;
|
|
21
|
+
this.populatedString = populatedString;
|
|
22
|
+
this.populationType = populationType;
|
|
23
|
+
}
|
|
24
|
+
get() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { populate } = this.resource.properties;
|
|
27
|
+
if (!populate) {
|
|
28
|
+
return this.populatedString;
|
|
29
|
+
}
|
|
30
|
+
if (!populate.all && !populate.list && !populate.show) {
|
|
31
|
+
return this.populatedString;
|
|
32
|
+
}
|
|
33
|
+
if (populate.all) {
|
|
34
|
+
return yield populate.all(this.populatedString);
|
|
35
|
+
}
|
|
36
|
+
if (this.populationType === PopulationType.LIST) {
|
|
37
|
+
if (populate.list) {
|
|
38
|
+
return yield populate.list(this.populatedString);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
if (populate.show) {
|
|
43
|
+
return yield populate.show(this.populatedString);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return this.populatedString;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.PopulationHelper = PopulationHelper;
|
|
@@ -2,12 +2,13 @@ import { Document, Model } from "mongoose";
|
|
|
2
2
|
import { IRequest } from "../middlewares/isAuth";
|
|
3
3
|
import { IRepository } from "../repositories/Repository";
|
|
4
4
|
import { ActionNames, ActionTypes, FieldTypes, FileTypes, HandlerStrategy, Virtuals } from "./helpers";
|
|
5
|
-
declare type orderTypes =
|
|
6
|
-
declare type VirtualFieldTypes =
|
|
7
|
-
declare type Severity =
|
|
8
|
-
declare type ButtonColors =
|
|
9
|
-
declare type ButtonVariants =
|
|
10
|
-
declare type ButtonSizes =
|
|
5
|
+
declare type orderTypes = "asc" | "desc";
|
|
6
|
+
declare type VirtualFieldTypes = "password" | "ref" | "Array";
|
|
7
|
+
declare type Severity = "success" | "info" | "warning" | "error";
|
|
8
|
+
declare type ButtonColors = "inherit" | "primary" | "secondary" | "success" | "error" | "info" | "warning";
|
|
9
|
+
declare type ButtonVariants = "text" | "outlined" | "contained";
|
|
10
|
+
declare type ButtonSizes = "small" | "medium" | "large";
|
|
11
|
+
declare type PopulateFunction = (populatedString: any) => Promise<any>;
|
|
11
12
|
interface Parent {
|
|
12
13
|
/**
|
|
13
14
|
* Name of the parent
|
|
@@ -19,6 +20,20 @@ interface Parent {
|
|
|
19
20
|
*/
|
|
20
21
|
icon: string;
|
|
21
22
|
}
|
|
23
|
+
interface IPopulate {
|
|
24
|
+
/**
|
|
25
|
+
* This function is called for all the endpoints to have an access over the populated string
|
|
26
|
+
*/
|
|
27
|
+
all?: PopulateFunction;
|
|
28
|
+
/**
|
|
29
|
+
* This function is called for the list endpoint to have an access over the populated string
|
|
30
|
+
*/
|
|
31
|
+
list?: PopulateFunction;
|
|
32
|
+
/**
|
|
33
|
+
* This function is called for the get one endpoint either in show or form an access over the populated string
|
|
34
|
+
*/
|
|
35
|
+
show?: PopulateFunction;
|
|
36
|
+
}
|
|
22
37
|
interface Action {
|
|
23
38
|
/**
|
|
24
39
|
* Specify if this action is accessible or not.
|
|
@@ -126,9 +141,9 @@ interface IFilters {
|
|
|
126
141
|
*/
|
|
127
142
|
scopes?: {
|
|
128
143
|
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
144
|
+
* Specify if this filter is accessible or not
|
|
145
|
+
* @default false
|
|
146
|
+
*/
|
|
132
147
|
isAccessible: boolean;
|
|
133
148
|
/**
|
|
134
149
|
* Automatic scope that filters by the specified key with one of the given options
|
|
@@ -147,9 +162,9 @@ interface IFilters {
|
|
|
147
162
|
*/
|
|
148
163
|
searchBar?: {
|
|
149
164
|
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
165
|
+
* Specify if this filter is accessible or not
|
|
166
|
+
* @default true
|
|
167
|
+
*/
|
|
153
168
|
isAccessible: boolean;
|
|
154
169
|
};
|
|
155
170
|
}
|
|
@@ -230,9 +245,9 @@ export interface IFieldValue {
|
|
|
230
245
|
*/
|
|
231
246
|
withTime?: boolean;
|
|
232
247
|
/**
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
248
|
+
* Specify the api route that to be called for getting the referenced values
|
|
249
|
+
* @default undefined
|
|
250
|
+
*/
|
|
236
251
|
apiRoute?: string;
|
|
237
252
|
/**
|
|
238
253
|
* Path of the value inside the model schema
|
|
@@ -337,7 +352,7 @@ interface ExtraAction {
|
|
|
337
352
|
/**
|
|
338
353
|
* Alert message appear after executing this action.
|
|
339
354
|
* @default 'Action was executed successfully'
|
|
340
|
-
|
|
355
|
+
*/
|
|
341
356
|
message?: string;
|
|
342
357
|
/**
|
|
343
358
|
* The severity of the alert. This defines the color and icon used.
|
|
@@ -473,11 +488,15 @@ export interface IResourceFile {
|
|
|
473
488
|
model?: {
|
|
474
489
|
[key: string]: IFieldValue;
|
|
475
490
|
} | IModel;
|
|
491
|
+
/**
|
|
492
|
+
* Override the populated object
|
|
493
|
+
*/
|
|
494
|
+
populate?: IPopulate;
|
|
476
495
|
};
|
|
477
496
|
/**
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
497
|
+
* Array of properties that should be appeared in the list action.
|
|
498
|
+
* @default 'The whole fields'
|
|
499
|
+
*/
|
|
481
500
|
listProperties?: string[];
|
|
482
501
|
/**
|
|
483
502
|
* Arrays of properties that should be appeared in the show action.
|