identity-admin 1.23.1 → 1.24.0
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.
|
@@ -37,4 +37,5 @@ export default class DashboardController {
|
|
|
37
37
|
show(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
38
38
|
deleteAll(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
39
39
|
delete(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
40
|
+
getNeighbors(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
40
41
|
}
|
|
@@ -35,6 +35,7 @@ const ResourceUtils_1 = require("../utils/ResourceUtils");
|
|
|
35
35
|
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
|
+
const helpers_1 = require("../types/helpers");
|
|
38
39
|
let DashboardController = DashboardController_1 = class DashboardController {
|
|
39
40
|
constructor(resource, repository, resources, modelConfigurations) {
|
|
40
41
|
this.resource = resource;
|
|
@@ -380,21 +381,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
380
381
|
if (afterMethod && record) {
|
|
381
382
|
extras = yield afterMethod(req, record);
|
|
382
383
|
}
|
|
383
|
-
|
|
384
|
-
const nextQuery = {};
|
|
385
|
-
const prevQuery = {};
|
|
386
|
-
const nextSortQuery = {};
|
|
387
|
-
const prevSortQuery = {};
|
|
388
|
-
nextQuery[sortBy] = { $gt: record[sortBy] };
|
|
389
|
-
prevQuery[sortBy] = { $lt: record[sortBy] };
|
|
390
|
-
nextSortQuery[sortBy] = 1;
|
|
391
|
-
prevSortQuery[sortBy] = -1;
|
|
392
|
-
const next = yield (model === null || model === void 0 ? void 0 : model.findOne(nextQuery).sort(nextSortQuery).limit(1));
|
|
393
|
-
const previous = yield (model === null || model === void 0 ? void 0 : model.findOne(prevQuery).sort(prevSortQuery).limit(1));
|
|
394
|
-
const hasNext = record && next && next._id ? true : false;
|
|
395
|
-
const hasPrevious = record && previous && previous._id ? true : false;
|
|
396
|
-
return ResponseUtils_1.default.ok(res, Object.assign(Object.assign({}, extras), { record: record ? record : null, hasNext,
|
|
397
|
-
hasPrevious, nextId: hasNext ? next === null || next === void 0 ? void 0 : next._id : undefined, previousId: hasPrevious ? previous === null || previous === void 0 ? void 0 : previous._id : undefined }));
|
|
384
|
+
return ResponseUtils_1.default.ok(res, Object.assign(Object.assign({}, extras), { record: record ? record : null }));
|
|
398
385
|
});
|
|
399
386
|
}
|
|
400
387
|
deleteAll(req, res) {
|
|
@@ -472,6 +459,72 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
472
459
|
return ResponseUtils_1.default.send(res, 200, "OK");
|
|
473
460
|
});
|
|
474
461
|
}
|
|
462
|
+
getNeighbors(req, res) {
|
|
463
|
+
var _a, _b, _c;
|
|
464
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
465
|
+
if (!this.validateRequest(req, res)) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const modelName = req.params.resource;
|
|
469
|
+
const recordId = req.params.id;
|
|
470
|
+
const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
|
|
471
|
+
const currentUser = req.user;
|
|
472
|
+
const model = resource === null || resource === void 0 ? void 0 : resource.properties.resource;
|
|
473
|
+
const neighborRecordType = req.query.type;
|
|
474
|
+
if (!resource || !neighborRecordType) {
|
|
475
|
+
return ResponseUtils_1.default.notFound(res, "Resource not found", []);
|
|
476
|
+
}
|
|
477
|
+
if (!currentUser) {
|
|
478
|
+
return ResponseUtils_1.default.unauthorized(res);
|
|
479
|
+
}
|
|
480
|
+
const permissionCheck = resource.properties.isAllowed
|
|
481
|
+
? yield resource.properties.isAllowed(currentUser)
|
|
482
|
+
: true;
|
|
483
|
+
if (!permissionCheck) {
|
|
484
|
+
return ResponseUtils_1.default.forbidden(res);
|
|
485
|
+
}
|
|
486
|
+
if (neighborRecordType !== helpers_1.NeighborTypes.NEXT &&
|
|
487
|
+
neighborRecordType !== helpers_1.NeighborTypes.PREVIOUS) {
|
|
488
|
+
return ResponseUtils_1.default.notFound(res, "Type in query should match NEXT or PREVIOUS", []);
|
|
489
|
+
}
|
|
490
|
+
const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
|
|
491
|
+
const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser, undefined, this.modelConfigurations);
|
|
492
|
+
var record = yield repository.findOne({
|
|
493
|
+
filter: {
|
|
494
|
+
_id: recordId,
|
|
495
|
+
},
|
|
496
|
+
populate: modifiedResource.properties.populatedString,
|
|
497
|
+
});
|
|
498
|
+
if (!record) {
|
|
499
|
+
return ResponseUtils_1.default.send(res, 404, "record not found");
|
|
500
|
+
}
|
|
501
|
+
record = record.toObject();
|
|
502
|
+
record = yield ResourceHelper_1.default.addExtraFields(modifiedResource.showProperties, modifiedResource.properties.model, record, StringUtils_1.default.lowerCaseFirstLetter(modifiedResource.properties.modelName), resource);
|
|
503
|
+
const sortBy = modifiedResource.properties
|
|
504
|
+
.defaultOrderBy;
|
|
505
|
+
const nextQuery = {};
|
|
506
|
+
const prevQuery = {};
|
|
507
|
+
const nextSortQuery = {};
|
|
508
|
+
const prevSortQuery = {};
|
|
509
|
+
nextQuery[sortBy] = { $gt: record[sortBy] };
|
|
510
|
+
prevQuery[sortBy] = { $lt: record[sortBy] };
|
|
511
|
+
nextSortQuery[sortBy] = 1;
|
|
512
|
+
prevSortQuery[sortBy] = -1;
|
|
513
|
+
var neighbor;
|
|
514
|
+
if (neighborRecordType === helpers_1.NeighborTypes.NEXT) {
|
|
515
|
+
neighbor = yield (model === null || model === void 0 ? void 0 : model.findOne(nextQuery).sort(nextSortQuery).limit(1));
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
neighbor = yield (model === null || model === void 0 ? void 0 : model.findOne(prevQuery).sort(prevSortQuery).limit(1));
|
|
519
|
+
}
|
|
520
|
+
const hasNeighbor = record && neighbor && neighbor._id ? true : false;
|
|
521
|
+
const neighborRecordId = hasNeighbor ? neighbor._id : undefined;
|
|
522
|
+
return ResponseUtils_1.default.ok(res, {
|
|
523
|
+
hasNeighbor,
|
|
524
|
+
neighborRecordId
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
}
|
|
475
528
|
};
|
|
476
529
|
DashboardController.DEFAULT_PAGE = 1;
|
|
477
530
|
DashboardController.DEFAULT_PER_PAGE = 30;
|
|
@@ -509,6 +562,11 @@ __decorate([
|
|
|
509
562
|
__param(0, (0, inversify_express_utils_1.request)()),
|
|
510
563
|
__param(1, (0, inversify_express_utils_1.response)())
|
|
511
564
|
], DashboardController.prototype, "delete", null);
|
|
565
|
+
__decorate([
|
|
566
|
+
(0, inversify_express_utils_1.httpGet)("/neighbors/:id"),
|
|
567
|
+
__param(0, (0, inversify_express_utils_1.request)()),
|
|
568
|
+
__param(1, (0, inversify_express_utils_1.response)())
|
|
569
|
+
], DashboardController.prototype, "getNeighbors", null);
|
|
512
570
|
DashboardController = DashboardController_1 = __decorate([
|
|
513
571
|
(0, inversify_1.injectable)(),
|
|
514
572
|
__param(0, (0, inversify_1.unmanaged)()),
|
package/lib/types/helpers.d.ts
CHANGED
package/lib/types/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HandlerStrategy = exports.FileTypes = exports.FieldTypes = exports.ActionTypes = exports.ActionNames = exports.Virtuals = void 0;
|
|
3
|
+
exports.NeighborTypes = exports.HandlerStrategy = exports.FileTypes = exports.FieldTypes = exports.ActionTypes = exports.ActionNames = exports.Virtuals = void 0;
|
|
4
4
|
var Virtuals;
|
|
5
5
|
(function (Virtuals) {
|
|
6
6
|
Virtuals["SHOW"] = "SHOW";
|
|
@@ -61,3 +61,8 @@ var HandlerStrategy;
|
|
|
61
61
|
HandlerStrategy["FILE_DOWNLOAD"] = "FILE_DOWNLOAD";
|
|
62
62
|
HandlerStrategy["CUSTOM_COMPONENT"] = "CUSTOM_COMPONENT";
|
|
63
63
|
})(HandlerStrategy = exports.HandlerStrategy || (exports.HandlerStrategy = {}));
|
|
64
|
+
var NeighborTypes;
|
|
65
|
+
(function (NeighborTypes) {
|
|
66
|
+
NeighborTypes["NEXT"] = "NEXT";
|
|
67
|
+
NeighborTypes["PREVIOUS"] = "PREVIOUS";
|
|
68
|
+
})(NeighborTypes = exports.NeighborTypes || (exports.NeighborTypes = {}));
|