identity-admin 1.9.1 → 1.11.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.
Files changed (37) hide show
  1. package/lib/controllers/DashboardController.d.ts +1 -1
  2. package/lib/controllers/DashboardController.js +94 -15
  3. package/lib/controllers/ResourceController.js +15 -10
  4. package/lib/helpers/ActionsGenerator.d.ts +2 -1
  5. package/lib/helpers/ActionsGenerator.js +12 -4
  6. package/lib/helpers/ResourceGenerator.d.ts +2 -1
  7. package/lib/helpers/ResourceGenerator.js +2 -2
  8. package/lib/helpers/ResourceHelper.d.ts +4 -0
  9. package/lib/helpers/ResourceHelper.js +75 -12
  10. package/lib/locales/en.json +2 -1
  11. package/lib/router/index.js +3 -0
  12. package/lib/types/IResourceFile.d.ts +281 -80
  13. package/lib/types/IResourceResponse.d.ts +99 -0
  14. package/lib/types/IResourceResponse.js +2 -0
  15. package/lib/types/helpers.d.ts +12 -0
  16. package/lib/types/helpers.js +14 -1
  17. package/lib/utils/ResponseUtils.d.ts +1 -0
  18. package/lib/utils/ResponseUtils.js +3 -0
  19. package/lib/view/asset-manifest.json +13 -8
  20. package/lib/view/index.html +52 -1
  21. package/lib/view/static/css/main.54de06ef.css +2 -0
  22. package/lib/view/static/css/main.54de06ef.css.map +1 -0
  23. package/lib/view/static/js/{148.b05fe2c8.chunk.js → 574.778b5963.chunk.js} +2 -1
  24. package/lib/view/static/js/574.778b5963.chunk.js.map +1 -0
  25. package/lib/view/static/js/678.521704a3.chunk.js +2 -0
  26. package/lib/view/static/js/678.521704a3.chunk.js.map +1 -0
  27. package/lib/view/static/js/798.54856416.chunk.js +2 -0
  28. package/lib/view/static/js/798.54856416.chunk.js.map +1 -0
  29. package/lib/view/static/js/admin.js +1 -0
  30. package/lib/view/static/js/main.4687f255.js +3 -0
  31. package/lib/view/static/js/{main.da8f09ec.js.LICENSE.txt → main.4687f255.js.LICENSE.txt} +4 -15
  32. package/lib/view/static/js/main.4687f255.js.map +1 -0
  33. package/package.json +1 -1
  34. package/lib/view/static/css/main.18dca458.css +0 -1
  35. package/lib/view/static/js/705.f86db82e.chunk.js +0 -1
  36. package/lib/view/static/js/802.3f287a2c.chunk.js +0 -1
  37. package/lib/view/static/js/main.da8f09ec.js +0 -2
@@ -27,7 +27,7 @@ export default class DashboardController {
27
27
  }, scope: string): {
28
28
  [key: string]: any;
29
29
  };
30
- protected getVisibileExtrsActions(currentUser: Document, record: any, resource: any, repository: any, modelName: string): Promise<any[] | undefined>;
30
+ protected getVisibileExtrsActions(currentUser: Document, record: any, resource: IResourceFile, repository: any, modelName: string): Promise<string[] | undefined>;
31
31
  index(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
32
32
  create(req: IRequest, res: Response): Promise<void>;
33
33
  update(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
@@ -23,18 +23,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  var DashboardController_1;
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  const inversify_express_utils_1 = require("inversify-express-utils");
26
- const mongoose_1 = require("mongoose");
27
26
  const ResponseUtils_1 = __importDefault(require("../utils/ResponseUtils"));
28
27
  const express_validator_1 = require("express-validator");
29
28
  const ResourceGenerator_1 = __importDefault(require("../helpers/ResourceGenerator"));
30
29
  const ResourceHelper_1 = __importDefault(require("../helpers/ResourceHelper"));
31
30
  const StringUtils_1 = __importDefault(require("../utils/StringUtils"));
32
- const mongoose_2 = __importDefault(require("mongoose"));
31
+ const mongoose_1 = __importDefault(require("mongoose"));
33
32
  const inversify_1 = require("inversify");
34
33
  const Repository_1 = __importDefault(require("../repositories/Repository"));
35
34
  const ResourceUtils_1 = require("../utils/ResourceUtils");
36
35
  const FiltersHelper_1 = __importDefault(require("../helpers/FiltersHelper"));
37
36
  const LocalizedStringHelper_1 = __importDefault(require("../helpers/LocalizedStringHelper"));
37
+ const ActionsGenerator_1 = __importDefault(require("../helpers/ActionsGenerator"));
38
38
  let DashboardController = DashboardController_1 = class DashboardController {
39
39
  constructor(resource, repository, resources) {
40
40
  this.resource = resource;
@@ -61,7 +61,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
61
61
  const schema = resource.properties.resource.schema.paths;
62
62
  const searchBy = ResourceHelper_1.default.getSchemaTitle(schema, this.resource);
63
63
  if (searchBy === '_id') {
64
- if (!mongoose_2.default.isValidObjectId(subString.source)) {
64
+ if (!mongoose_1.default.isValidObjectId(subString.source)) {
65
65
  return filter;
66
66
  }
67
67
  filter[searchBy] = subString.source;
@@ -102,7 +102,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
102
102
  if (!extraAction.isVisible) {
103
103
  break;
104
104
  }
105
- const isVisible = extraAction.isVisible(data);
105
+ const isVisible = yield extraAction.isVisible(data);
106
106
  if (isVisible) {
107
107
  extraActionsArray.push(extraAction.key);
108
108
  }
@@ -127,8 +127,15 @@ let DashboardController = DashboardController_1 = class DashboardController {
127
127
  if (!resource) {
128
128
  return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
129
129
  }
130
+ if (!currentUser) {
131
+ return ResponseUtils_1.default.unauthorized(res);
132
+ }
133
+ const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
134
+ if (!permissionCheck) {
135
+ return ResponseUtils_1.default.forbidden(res);
136
+ }
130
137
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
131
- const modifiedResource = ResourceGenerator_1.default.generate(resource);
138
+ const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser);
132
139
  const sort = req.query.order;
133
140
  const sortBy = req.query.orderBy;
134
141
  const sortQuery = {};
@@ -140,7 +147,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
140
147
  var filter = {};
141
148
  if (scope && resource.properties.filters && resource.properties.filters.scopes && resource.properties.filters.scopes.isAccessible) {
142
149
  if (resource.properties.filters.scopes.manual) {
143
- filter = resource.properties.filters.scopes.manual.handler(filter, scope);
150
+ filter = yield resource.properties.filters.scopes.manual.handler(filter, scope);
144
151
  }
145
152
  else if (resource.properties.filters.scopes.auto) {
146
153
  const key = resource.properties.filters.scopes.auto.key;
@@ -154,8 +161,8 @@ let DashboardController = DashboardController_1 = class DashboardController {
154
161
  }
155
162
  filter = FiltersHelper_1.default.appendFilters(filter, filters);
156
163
  const crudOperations = resource.properties.crudOperations;
157
- if (crudOperations && crudOperations.index) {
158
- filter = crudOperations.index.before(req, filter, currentUser);
164
+ if (crudOperations && crudOperations.index && crudOperations.index.before) {
165
+ filter = yield crudOperations.index.before(req, filter, currentUser);
159
166
  }
160
167
  var records = [];
161
168
  var pageInfo = undefined;
@@ -189,6 +196,9 @@ let DashboardController = DashboardController_1 = class DashboardController {
189
196
  documents.push(record);
190
197
  }
191
198
  }
199
+ if (crudOperations && crudOperations.index && crudOperations.index.after) {
200
+ documents = yield crudOperations.index.after(req, documents, currentUser);
201
+ }
192
202
  return ResponseUtils_1.default.send(res, 200, 'OK', {
193
203
  records: documents,
194
204
  pageInfo,
@@ -204,21 +214,33 @@ let DashboardController = DashboardController_1 = class DashboardController {
204
214
  }
205
215
  const modelName = req.params.resource;
206
216
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
217
+ const currentUser = req.user;
207
218
  if (!resource) {
208
219
  return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
209
220
  }
221
+ if (!currentUser) {
222
+ return ResponseUtils_1.default.unauthorized(res);
223
+ }
224
+ const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
225
+ if (!permissionCheck) {
226
+ return ResponseUtils_1.default.forbidden(res);
227
+ }
228
+ const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
229
+ const createPermission = actions.new.isAccessible;
230
+ if (!createPermission) {
231
+ return ResponseUtils_1.default.forbidden(res);
232
+ }
210
233
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
211
- const modifiedResource = ResourceGenerator_1.default.generate(resource);
212
234
  var recordParams = req.body;
213
- const currentUser = req.user;
214
235
  recordParams = LocalizedStringHelper_1.default.mapLocalizableString(recordParams, resource);
215
236
  const crudOperations = resource.properties.crudOperations;
216
- if (crudOperations && crudOperations.create) {
217
- recordParams = crudOperations.create.before(req, recordParams, currentUser);
237
+ if (crudOperations && crudOperations.create && crudOperations.create.before) {
238
+ recordParams = yield crudOperations.create.before(req, recordParams, currentUser);
218
239
  }
219
240
  var record;
220
241
  if (recordParams.password) {
221
- const user = new mongoose_1.Mongoose.prototype.model(modifiedResource.properties.modelName)(recordParams);
242
+ //const user = new Mongoose.prototype.model(modifiedResource.properties.modelName)(recordParams);
243
+ const user = new resource.properties.resource(recordParams);
222
244
  const set = yield user.setPassword(recordParams.password);
223
245
  record = yield repository.saveInstance(user);
224
246
  }
@@ -228,6 +250,9 @@ let DashboardController = DashboardController_1 = class DashboardController {
228
250
  if (!record.isValid() || !record.document) {
229
251
  return ResponseUtils_1.default.unprocessable(res, 'Invalid Data', record.getErrors());
230
252
  }
253
+ if (crudOperations && crudOperations.create && crudOperations.create.after) {
254
+ record = yield crudOperations.create.after(req, record, currentUser);
255
+ }
231
256
  return ResponseUtils_1.default.created(res, {
232
257
  record
233
258
  });
@@ -244,13 +269,30 @@ let DashboardController = DashboardController_1 = class DashboardController {
244
269
  if (!resource) {
245
270
  return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
246
271
  }
272
+ var recordParams = req.body;
273
+ const currentUser = req.user;
274
+ if (!currentUser) {
275
+ return ResponseUtils_1.default.unauthorized(res);
276
+ }
277
+ const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
278
+ if (!permissionCheck) {
279
+ return ResponseUtils_1.default.forbidden(res);
280
+ }
281
+ const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
282
+ const editPermission = actions.edit.isAccessible;
283
+ if (!editPermission) {
284
+ return ResponseUtils_1.default.forbidden(res);
285
+ }
247
286
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
248
287
  const recordId = req.params.id;
249
- var recordParams = req.body;
250
288
  var record = yield repository.findById(recordId);
251
289
  if (!record) {
252
290
  return ResponseUtils_1.default.send(res, 404, 'record Not Found');
253
291
  }
292
+ const crudOperations = resource.properties.crudOperations;
293
+ if (crudOperations && crudOperations.update && crudOperations.update.before) {
294
+ recordParams = yield crudOperations.update.before(req, recordParams, currentUser);
295
+ }
254
296
  const recordSaveResult = yield repository.update(record, recordParams);
255
297
  if (!recordSaveResult.isValid()) {
256
298
  return ResponseUtils_1.default.unprocessable(res, 'Invalid Data', recordSaveResult.getErrors());
@@ -258,6 +300,9 @@ let DashboardController = DashboardController_1 = class DashboardController {
258
300
  // if (resource.properties.modelName === ModelNames.Settings) {
259
301
  // await AppSettings.run()
260
302
  // }
303
+ // if (crudOperations && crudOperations.update && crudOperations.update.after) {
304
+ // recordSaveResult = await crudOperations.update.after(req, recordSaveResult, currentUser)
305
+ // }
261
306
  return ResponseUtils_1.default.ok(res, {
262
307
  record: recordSaveResult
263
308
  });
@@ -272,11 +317,19 @@ let DashboardController = DashboardController_1 = class DashboardController {
272
317
  const modelName = req.params.resource;
273
318
  const recordId = req.params.id;
274
319
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
320
+ const currentUser = req.user;
275
321
  if (!resource) {
276
322
  return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
277
323
  }
324
+ if (!currentUser) {
325
+ return ResponseUtils_1.default.unauthorized(res);
326
+ }
327
+ const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
328
+ if (!permissionCheck) {
329
+ return ResponseUtils_1.default.forbidden(res);
330
+ }
278
331
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
279
- const modifiedResource = ResourceGenerator_1.default.generate(resource);
332
+ const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser);
280
333
  var record = yield repository.findOne({
281
334
  filter: {
282
335
  _id: recordId
@@ -309,6 +362,19 @@ let DashboardController = DashboardController_1 = class DashboardController {
309
362
  if (!resource) {
310
363
  return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
311
364
  }
365
+ const currentUser = req.user;
366
+ if (!currentUser) {
367
+ return ResponseUtils_1.default.unauthorized(res);
368
+ }
369
+ const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
370
+ if (!permissionCheck) {
371
+ return ResponseUtils_1.default.forbidden(res);
372
+ }
373
+ const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
374
+ const bulkDeletePermission = actions.bulkDelete.isAccessible;
375
+ if (!bulkDeletePermission) {
376
+ return ResponseUtils_1.default.forbidden(res);
377
+ }
312
378
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
313
379
  for (var i = 0; i < recordIds.length; i++) {
314
380
  const recordId = recordIds[i];
@@ -333,6 +399,19 @@ let DashboardController = DashboardController_1 = class DashboardController {
333
399
  if (!resource) {
334
400
  return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
335
401
  }
402
+ const currentUser = req.user;
403
+ if (!currentUser) {
404
+ return ResponseUtils_1.default.unauthorized(res);
405
+ }
406
+ const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
407
+ if (!permissionCheck) {
408
+ return ResponseUtils_1.default.forbidden(res);
409
+ }
410
+ const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
411
+ const deletePermission = actions.delete.isAccessible;
412
+ if (!deletePermission) {
413
+ return ResponseUtils_1.default.forbidden(res);
414
+ }
336
415
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
337
416
  const record = yield repository.findById(recordId);
338
417
  if (!record) {
@@ -58,20 +58,24 @@ let ResourceController = class ResourceController {
58
58
  return __awaiter(this, void 0, void 0, function* () {
59
59
  var modifiedResource = {};
60
60
  modifiedResource.modelParents = {};
61
+ const currentUser = req.user;
61
62
  if (this.configurations) {
62
63
  modifiedResource.appConfigurations = this.configurations;
63
64
  }
64
65
  for (var i = 0; i < this.resourceFiles.length; i++) {
65
66
  const resource = this.resourceFiles[i];
66
- const adaptedResource = ResourceGenerator_1.default.generate(resource);
67
- const modelName = StringUtils_1.default.lowerCaseFirstLetter(adaptedResource.properties.modelName);
68
- modifiedResource[modelName] = adaptedResource;
69
- if (modifiedResource.modelParents[adaptedResource.properties.parent.name]) {
70
- modifiedResource.modelParents[adaptedResource.properties.parent.name].push(modelName);
71
- }
72
- else {
73
- modifiedResource.modelParents[adaptedResource.properties.parent.name] = [];
74
- modifiedResource.modelParents[adaptedResource.properties.parent.name].push(modelName);
67
+ const visibiltyCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
68
+ if (visibiltyCheck) {
69
+ const adaptedResource = ResourceGenerator_1.default.generate(resource, currentUser);
70
+ const modelName = StringUtils_1.default.lowerCaseFirstLetter(adaptedResource.properties.modelName);
71
+ modifiedResource[modelName] = adaptedResource;
72
+ if (modifiedResource.modelParents[adaptedResource.properties.parent.name]) {
73
+ modifiedResource.modelParents[adaptedResource.properties.parent.name].push(modelName);
74
+ }
75
+ else {
76
+ modifiedResource.modelParents[adaptedResource.properties.parent.name] = [];
77
+ modifiedResource.modelParents[adaptedResource.properties.parent.name].push(modelName);
78
+ }
75
79
  }
76
80
  }
77
81
  return ResponseUtils_1.default.send(res, 200, 'OK', {
@@ -85,8 +89,9 @@ let ResourceController = class ResourceController {
85
89
  const resourceName = modelName + 'Resource';
86
90
  const resourceFilePath = '@pbb/materialUi/' + resourceName;
87
91
  const resource = yield Promise.resolve().then(() => __importStar(require(resourceFilePath)));
92
+ const currentUser = req.user;
88
93
  return ResponseUtils_1.default.send(res, 200, 'OK', {
89
- options: ResourceGenerator_1.default.generate(resource[resourceName])
94
+ options: ResourceGenerator_1.default.generate(resource[resourceName], currentUser)
90
95
  });
91
96
  });
92
97
  }
@@ -1,6 +1,7 @@
1
+ import { Document } from "mongoose";
1
2
  import { IResourceFile } from "../types/IResourceFile";
2
3
  export default class ActionsGenerator {
3
- static generateActions(actionsCheck: any, resource: IResourceFile): {
4
+ static generateActions(actionsCheck: any, resource: IResourceFile, currentUser: Document): {
4
5
  [key: string]: any;
5
6
  };
6
7
  private static addExtraActions;
@@ -30,8 +30,8 @@ const i18n_1 = __importStar(require("i18n"));
30
30
  const ResourceHelper_1 = __importDefault(require("./ResourceHelper"));
31
31
  var pluralize = require('pluralize');
32
32
  class ActionsGenerator {
33
- static generateActions(actionsCheck, resource) {
34
- const actions = this.getActions(actionsCheck ? JSON.parse(JSON.stringify(resource.properties.actions)) : undefined); //resource.properties.actions? ResourcesHelper.getActions(JSON.parse(JSON.stringify(resource.properties.actions))): ResourcesHelper.getActions(undefined)
33
+ static generateActions(actionsCheck, resource, currentUser) {
34
+ const actions = this.getActions(actionsCheck ? resource.properties.actions : undefined, currentUser); //resource.properties.actions? ResourcesHelper.getActions(JSON.parse(JSON.stringify(resource.properties.actions))): ResourcesHelper.getActions(undefined)
35
35
  for (const key in actions) {
36
36
  if (key === 'extras') {
37
37
  actions.extras = actions.extras ? this.addExtraActions(JSON.parse(JSON.stringify(resource.properties.actions.extras))) : actions.extras;
@@ -54,7 +54,7 @@ class ActionsGenerator {
54
54
  });
55
55
  return extraActionsObject;
56
56
  }
57
- static getActions(actions) {
57
+ static getActions(actions, currentUser) {
58
58
  var actionObject = {
59
59
  show: { isAccessible: true },
60
60
  new: { isAccessible: true },
@@ -66,7 +66,15 @@ class ActionsGenerator {
66
66
  return actionObject;
67
67
  }
68
68
  for (const key in actions) {
69
- if (actions[key].hasOwnProperty('isAccessible') || key === 'extras') {
69
+ if (actions[key].hasOwnProperty('isAccessible') && key !== 'extras') {
70
+ actionObject[key] = actions[key];
71
+ }
72
+ else if (actions[key].isAllowed && key !== 'extras') {
73
+ actionObject[key] = {
74
+ isAccessible: actions[key].isAllowed(currentUser)
75
+ };
76
+ }
77
+ else if (key === 'extras') {
70
78
  actionObject[key] = actions[key];
71
79
  }
72
80
  }
@@ -1,4 +1,5 @@
1
+ import { Document } from "mongoose";
1
2
  import { IResourceFile } from "../types/IResourceFile";
2
3
  export default class ResourceGenerator {
3
- static generate(resource: IResourceFile): any;
4
+ static generate(resource: IResourceFile, currentUser: Document): any;
4
5
  }
@@ -37,7 +37,7 @@ const SetupParent = {
37
37
  //value: __({phrase: "Setup", locale: i18n.getLocale()})
38
38
  };
39
39
  class ResourceGenerator {
40
- static generate(resource) {
40
+ static generate(resource, currentUser) {
41
41
  var _a, _b, _c, _d, _e, _f, _g;
42
42
  const SetupParent = {
43
43
  name: 'Setup',
@@ -102,7 +102,7 @@ class ResourceGenerator {
102
102
  const options = ((_b = (_a = resource.properties.filters) === null || _a === void 0 ? void 0 : _a.scopes) === null || _b === void 0 ? void 0 : _b.auto) ? (_d = (_c = resource.properties.filters) === null || _c === void 0 ? void 0 : _c.scopes) === null || _d === void 0 ? void 0 : _d.auto.options : (_g = (_f = (_e = resource.properties.filters) === null || _e === void 0 ? void 0 : _e.scopes) === null || _f === void 0 ? void 0 : _f.manual) === null || _g === void 0 ? void 0 : _g.options;
103
103
  modifiedResource.properties.filters.scopes.options = ResourceHelper_1.default.setScopeFilterOptions(modelName, options);
104
104
  }
105
- const actions = ActionsGenerator_1.default.generateActions(actionsCheck, resource);
105
+ const actions = ActionsGenerator_1.default.generateActions(actionsCheck, resource, currentUser);
106
106
  modifiedResource.properties.actions = actions;
107
107
  return modifiedResource;
108
108
  }
@@ -2,6 +2,8 @@ import { IResourceFile } from "../types/IResourceFile";
2
2
  export default class ResourcesHelper {
3
3
  static getSchemaTitle(schema: any, resource: any): any;
4
4
  static prepareProperties(properties: string[], modelName: string, model: any, resource: IResourceFile): {}[];
5
+ private static getPropertyObject;
6
+ private static getRawName;
5
7
  static getFieldType(schemaField: any): any;
6
8
  static prepareFilterProperties(properties: string[], schema: any): string[];
7
9
  static checkResourceTranslation(resource: IResourceFile, key: string): string | undefined;
@@ -20,4 +22,6 @@ export default class ResourcesHelper {
20
22
  static getModelPath(modelName: string): any;
21
23
  static removeUnWantedFieldsFromCreateOrUpdate(arrayOfFields: string[]): string[];
22
24
  static checkCreateBeforeHandler(resource: any): boolean;
25
+ private static checkNestedField;
26
+ private static getSchemaOfNestedProperty;
23
27
  }
@@ -51,22 +51,49 @@ class ResourcesHelper {
51
51
  var preparedProperties = [];
52
52
  properties.forEach(key => {
53
53
  if (model[key]) {
54
- const refCheck = model[key].type === helpers_1.FieldTypes.REFERENCE;
55
- var path = undefined;
56
- if (refCheck) {
57
- path = model[key].path;
58
- }
59
- const translation = this.checkResourceTranslation(resource, key);
60
- const propertyObject = {
61
- key,
62
- value: translation ? translation : StringUtils_1.default.checkRefId(key) ? StringUtils_1.default.convertCamelCaseToWord(key.slice(0, -2)) : StringUtils_1.default.convertCamelCaseToWord(key),
63
- path: path
64
- };
65
- preparedProperties.push(propertyObject);
54
+ // const refCheck = model[key].type === FieldTypes.REFERENCE
55
+ // var path = undefined
56
+ // if (refCheck) {
57
+ // path = model[key].path
58
+ // }
59
+ // const translation = this.checkResourceTranslation(resource, key)
60
+ // const propertyObject = {
61
+ // key,
62
+ // value: translation? translation: StringUtils.checkRefId(key)? StringUtils.convertCamelCaseToWord(key.slice(0, -2)): StringUtils.convertCamelCaseToWord(key),
63
+ // path: path
64
+ // }
65
+ preparedProperties.push(this.getPropertyObject(key, model[key], resource));
66
+ }
67
+ else if (key.includes('.') && this.checkNestedField(key, model)) {
68
+ const nestedModel = this.getSchemaOfNestedProperty(key, model);
69
+ preparedProperties.push(this.getPropertyObject(key, nestedModel, resource));
66
70
  }
67
71
  });
68
72
  return preparedProperties;
69
73
  }
74
+ static getPropertyObject(key, model, resource) {
75
+ const refCheck = model.type === helpers_1.FieldTypes.REFERENCE;
76
+ var path = undefined;
77
+ if (refCheck) {
78
+ path = model.path;
79
+ }
80
+ const translation = this.checkResourceTranslation(resource, key);
81
+ var rawKey = this.getRawName(key);
82
+ const translatedKey = rawKey ? rawKey : key;
83
+ const propertyObject = {
84
+ key,
85
+ value: translation ? translation : model.value ? model.value : StringUtils_1.default.checkRefId(translatedKey) ? StringUtils_1.default.convertCamelCaseToWord(translatedKey.slice(0, -2)) : StringUtils_1.default.convertCamelCaseToWord(translatedKey),
86
+ path: path
87
+ };
88
+ return propertyObject;
89
+ }
90
+ static getRawName(key) {
91
+ if (key.includes('.')) {
92
+ const nestedProperties = key.split('.');
93
+ return (nestedProperties[nestedProperties.length - 1]);
94
+ }
95
+ return undefined;
96
+ }
70
97
  static getFieldType(schemaField) {
71
98
  if (schemaField.instance === 'Embedded') {
72
99
  return helpers_1.FieldTypes.NESTEDSCHEMA;
@@ -301,5 +328,41 @@ class ResourcesHelper {
301
328
  }
302
329
  return false;
303
330
  }
331
+ static checkNestedField(nestedProperty, model) {
332
+ const nestedProperties = nestedProperty.split('.');
333
+ if (nestedProperties.length === 0) {
334
+ return false;
335
+ }
336
+ const parentProperty = nestedProperties[0];
337
+ if (!model[parentProperty] || (!model[parentProperty].schema && nestedProperties.length > 1)) {
338
+ return false;
339
+ }
340
+ if (nestedProperties.length === 1) {
341
+ return true;
342
+ }
343
+ var nextProperty = '';
344
+ for (var i = 1; i < nestedProperties.length; i++) {
345
+ nextProperty = nextProperty + nestedProperties[i];
346
+ if (i !== nestedProperties.length - 1) {
347
+ nextProperty = nextProperty + '.';
348
+ }
349
+ }
350
+ return this.checkNestedField(nextProperty, model[parentProperty].schema);
351
+ }
352
+ static getSchemaOfNestedProperty(nestedProperty, model) {
353
+ const nestedProperties = nestedProperty.split('.');
354
+ const parentProperty = nestedProperties[0];
355
+ if (nestedProperties.length === 1) {
356
+ return model[parentProperty];
357
+ }
358
+ var nextProperty = '';
359
+ for (var i = 1; i < nestedProperties.length; i++) {
360
+ nextProperty = nextProperty + nestedProperties[i];
361
+ if (i !== nestedProperties.length - 1) {
362
+ nextProperty = nextProperty + '.';
363
+ }
364
+ }
365
+ return this.getSchemaOfNestedProperty(nextProperty, model[parentProperty].schema);
366
+ }
304
367
  }
305
368
  exports.default = ResourcesHelper;
@@ -47,5 +47,6 @@
47
47
  "Unauthorized": "Unauthorized",
48
48
  "unprocessable": "unprocessable",
49
49
  "Server Error": "Server Error",
50
- "actions_new": "actions_new"
50
+ "actions_new": "actions_new",
51
+ "Setup": "Setup"
51
52
  }
@@ -47,6 +47,9 @@ const createMainRouter = (router, controller) => {
47
47
  .route(`/api/:resource`)
48
48
  .get((req, res) => controller.index(req, res))
49
49
  .post((req, res) => controller.create(req, res));
50
+ router
51
+ .route('/api/all')
52
+ .delete((req, res) => controller.deleteAll(req, res));
50
53
  router
51
54
  .route("/api/:resource/:id")
52
55
  .get((req, res) => controller.show(req, res))