identity-admin 1.4.3 → 1.5.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.
@@ -242,7 +242,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
242
242
  });
243
243
  }
244
244
  show(req, res) {
245
- var _a, _b, _c;
245
+ var _a, _b, _c, _d, _e;
246
246
  return __awaiter(this, void 0, void 0, function* () {
247
247
  if (!this.validateRequest(req, res)) {
248
248
  return;
@@ -266,11 +266,13 @@ let DashboardController = DashboardController_1 = class DashboardController {
266
266
  }
267
267
  record = record.toObject();
268
268
  //record = await this.getExtras(record._id.toString(), record, this.getExtraRepository())
269
- record = yield ResourceHelper_1.default.addExtraFields(modifiedResource.showProperties, modifiedResource.properties.model, record, StringUtils_1.default.lowerCaseFirstLetter(modifiedResource.properties.modelName));
270
- return ResponseUtils_1.default.ok(res, {
271
- record: record ? record : null,
272
- // options: modifiedResource
273
- });
269
+ record = yield ResourceHelper_1.default.addExtraFields(modifiedResource.showProperties, modifiedResource.properties.model, record, StringUtils_1.default.lowerCaseFirstLetter(modifiedResource.properties.modelName), resource);
270
+ const afterMethod = (_e = (_d = resource.properties.crudOperations) === null || _d === void 0 ? void 0 : _d.show) === null || _e === void 0 ? void 0 : _e.after;
271
+ let extras = {};
272
+ if (afterMethod && record) {
273
+ extras = yield afterMethod(record);
274
+ }
275
+ return ResponseUtils_1.default.ok(res, Object.assign(Object.assign({}, extras), { record: record ? record : null }));
274
276
  });
275
277
  }
276
278
  delete(req, res) {
@@ -10,7 +10,7 @@ export default class ResourcesHelper {
10
10
  scopes: {};
11
11
  searchBar: {};
12
12
  };
13
- static addExtraFields(showProperties: any, model: any, record: any, filterBy: string): Promise<any>;
13
+ static addExtraFields(showProperties: any, model: any, record: any, filterBy: string, resource: IResourceFile): Promise<any>;
14
14
  static getTitle(schema: any): "title" | "name" | "_id" | "email";
15
15
  static exchangeFirstFieldWithTitle(arrayOfFields: any, title: string): any;
16
16
  static addVirtualFields(arrayOfFields: string[], model: any): any[];
@@ -123,7 +123,7 @@ class ResourcesHelper {
123
123
  }
124
124
  return filterObject;
125
125
  }
126
- static addExtraFields(showProperties, model, record, filterBy) {
126
+ static addExtraFields(showProperties, model, record, filterBy, resource) {
127
127
  return __awaiter(this, void 0, void 0, function* () {
128
128
  for (var i = 0; i < showProperties.length; i++) {
129
129
  // if (!model.hasOwnProperty(showProperties[i].key)) {
@@ -139,8 +139,19 @@ class ResourcesHelper {
139
139
  // }
140
140
  const key = showProperties[i].key;
141
141
  if ((model[key].type === 'ref' && model.virtuals && model.virtuals[key]) || (model[key].type === 'Array' && model.virtuals && model.virtuals[key] && model[key].arrayType === 'ref')) {
142
- const resourceModel = model.virtuals[key].resource;
143
- const repository = new Repository_1.default(resourceModel);
142
+ const resourceModel = resource.properties.model;
143
+ if (!resourceModel) {
144
+ return;
145
+ }
146
+ const virtuals = resourceModel.virtuals;
147
+ if (!virtuals) {
148
+ return;
149
+ }
150
+ const virtualModel = virtuals[key].resource;
151
+ if (!virtualModel) {
152
+ return;
153
+ }
154
+ const repository = new Repository_1.default(virtualModel);
144
155
  filterBy = filterBy + "Id";
145
156
  const filterQuery = {};
146
157
  filterQuery[filterBy] = record._id;
@@ -22,6 +22,12 @@ interface ICrudOperations {
22
22
  create?: {
23
23
  before: (params: any, currentUser: Document) => any;
24
24
  };
25
+ show?: {
26
+ after: (record: Document) => Promise<{
27
+ record: Document;
28
+ [key: string]: any;
29
+ }>;
30
+ };
25
31
  }
26
32
  export interface ActionData {
27
33
  record: any;
@@ -47,7 +53,7 @@ interface IFieldValue {
47
53
  isEditable?: boolean;
48
54
  type?: string;
49
55
  }
50
- interface IVirtualValue {
56
+ export interface IVirtualValue {
51
57
  type: VirtualFieldTypes;
52
58
  arrayType?: string;
53
59
  showIn: Virtuals;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",