identity-admin 1.23.0 → 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;
@@ -348,6 +349,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
348
349
  const recordId = req.params.id;
349
350
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
350
351
  const currentUser = req.user;
352
+ const model = resource === null || resource === void 0 ? void 0 : resource.properties.resource;
351
353
  if (!resource) {
352
354
  return ResponseUtils_1.default.notFound(res, "Resource not found", []);
353
355
  }
@@ -457,6 +459,72 @@ let DashboardController = DashboardController_1 = class DashboardController {
457
459
  return ResponseUtils_1.default.send(res, 200, "OK");
458
460
  });
459
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
+ }
460
528
  };
461
529
  DashboardController.DEFAULT_PAGE = 1;
462
530
  DashboardController.DEFAULT_PER_PAGE = 30;
@@ -494,6 +562,11 @@ __decorate([
494
562
  __param(0, (0, inversify_express_utils_1.request)()),
495
563
  __param(1, (0, inversify_express_utils_1.response)())
496
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);
497
570
  DashboardController = DashboardController_1 = __decorate([
498
571
  (0, inversify_1.injectable)(),
499
572
  __param(0, (0, inversify_1.unmanaged)()),
@@ -52,3 +52,7 @@ export declare enum HandlerStrategy {
52
52
  FILE_DOWNLOAD = "FILE_DOWNLOAD",
53
53
  CUSTOM_COMPONENT = "CUSTOM_COMPONENT"
54
54
  }
55
+ export declare enum NeighborTypes {
56
+ NEXT = "NEXT",
57
+ PREVIOUS = "PREVIOUS"
58
+ }
@@ -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 = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",