identity-admin 1.21.0 → 1.22.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.
@@ -1,8 +1,9 @@
1
- import { Response } from 'express';
2
- import { Document } from 'mongoose';
3
- import { IResourceFile } from '../types/IResourceFile';
4
- import { IDashboardRepository } from '../repositories/Repository';
5
- import { IRequest } from '../middlewares/isAuth';
1
+ import { Response } from "express";
2
+ import { Document } from "mongoose";
3
+ import { IResourceFile } from "../types/IResourceFile";
4
+ import { IDashboardRepository } from "../repositories/Repository";
5
+ import { IRequest } from "../middlewares/isAuth";
6
+ import { IModelConfigurationDocument } from "../models/modelConfiguration/IModelConfigurations";
6
7
  export interface PaginateParams {
7
8
  page: number;
8
9
  perPage: number;
@@ -11,10 +12,12 @@ export default class DashboardController {
11
12
  private resource?;
12
13
  private repository?;
13
14
  private resources?;
15
+ private modelConfigurations?;
14
16
  protected static DEFAULT_PAGE: number;
15
17
  protected static DEFAULT_PER_PAGE: number;
16
18
  constructor(resource?: IResourceFile, repository?: IDashboardRepository);
17
19
  constructor(resource?: IResourceFile, repository?: IDashboardRepository, resources?: IResourceFile[]);
20
+ constructor(resource?: IResourceFile, repository?: IDashboardRepository, resources?: IResourceFile[], modelConfigurations?: Map<string, IModelConfigurationDocument>);
18
21
  protected validateRequest(req: IRequest, res: Response): boolean;
19
22
  protected paginateParams(request: IRequest): PaginateParams;
20
23
  protected getSearchableSubStringFilter(resource: IResourceFile, filter: {
@@ -36,10 +36,11 @@ 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
  let DashboardController = DashboardController_1 = class DashboardController {
39
- constructor(resource, repository, resources) {
39
+ constructor(resource, repository, resources, modelConfigurations) {
40
40
  this.resource = resource;
41
41
  this.repository = repository;
42
42
  this.resources = resources;
43
+ this.modelConfigurations = modelConfigurations;
43
44
  if (!repository && resource) {
44
45
  this.repository = new Repository_1.default(resource.properties.resource);
45
46
  }
@@ -53,14 +54,19 @@ let DashboardController = DashboardController_1 = class DashboardController {
53
54
  return true;
54
55
  }
55
56
  paginateParams(request) {
56
- const page = request.query.page ? +request.query.page : DashboardController_1.DEFAULT_PAGE;
57
- const perPage = request.query.perPage ? +request.query.perPage : DashboardController_1.DEFAULT_PER_PAGE;
57
+ const page = request.query.page
58
+ ? +request.query.page
59
+ : DashboardController_1.DEFAULT_PAGE;
60
+ const perPage = request.query.perPage
61
+ ? +request.query.perPage
62
+ : DashboardController_1.DEFAULT_PER_PAGE;
58
63
  return { page, perPage };
59
64
  }
60
65
  getSearchableSubStringFilter(resource, filter, subString) {
66
+ var _a;
61
67
  const schema = resource.properties.resource.schema.paths;
62
- const searchBy = ResourceHelper_1.default.getSchemaTitle(schema, this.resource);
63
- if (searchBy === '_id') {
68
+ const searchBy = ResourceHelper_1.default.getSchemaTitle(schema, this.resource, (_a = this.modelConfigurations) === null || _a === void 0 ? void 0 : _a.get(resource.properties.modelName));
69
+ if (searchBy === "_id") {
64
70
  if (!mongoose_1.default.isValidObjectId(subString.source)) {
65
71
  return filter;
66
72
  }
@@ -89,8 +95,8 @@ let DashboardController = DashboardController_1 = class DashboardController {
89
95
  resource: {
90
96
  name: modelName,
91
97
  path: StringUtils_1.default.lowerCaseFirstLetter(modelName),
92
- repository
93
- }
98
+ repository,
99
+ },
94
100
  };
95
101
  if (!resource.properties.actions || !resource.properties.actions.extras) {
96
102
  return undefined;
@@ -118,35 +124,44 @@ let DashboardController = DashboardController_1 = class DashboardController {
118
124
  return;
119
125
  }
120
126
  const paginateParams = this.paginateParams(req);
121
- const searchableSubString = req.query.filter ? new RegExp(req.query.filter, 'i') : undefined;
127
+ const searchableSubString = req.query.filter
128
+ ? new RegExp(req.query.filter, "i")
129
+ : undefined;
122
130
  const scope = req.query.scope;
123
131
  const currentUser = req.user;
124
132
  const modelName = req.params.resource;
125
133
  const filtersQuery = req.query.filters;
126
- const filters = filtersQuery ? filtersQuery.split("^^") : undefined;
134
+ const filters = filtersQuery
135
+ ? filtersQuery.split("^^")
136
+ : undefined;
127
137
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
128
138
  if (!resource) {
129
- return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
139
+ return ResponseUtils_1.default.notFound(res, "Resource not found", []);
130
140
  }
131
141
  if (!currentUser) {
132
142
  return ResponseUtils_1.default.unauthorized(res);
133
143
  }
134
- const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
144
+ const permissionCheck = resource.properties.isAllowed
145
+ ? yield resource.properties.isAllowed(currentUser)
146
+ : true;
135
147
  if (!permissionCheck) {
136
148
  return ResponseUtils_1.default.forbidden(res);
137
149
  }
138
150
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
139
- const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser);
151
+ const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser, undefined, this.modelConfigurations);
140
152
  const sort = req.query.order;
141
153
  const sortBy = req.query.orderBy;
142
154
  const sortQuery = {};
143
155
  sortQuery[sortBy] = sort;
144
- if (sortBy !== '_id') {
145
- sortQuery._id = 'asc';
156
+ if (sortBy !== "_id") {
157
+ sortQuery._id = "asc";
146
158
  }
147
159
  const populate = req.query.populate;
148
160
  var filter = {};
149
- if (scope && resource.properties.filters && resource.properties.filters.scopes && resource.properties.filters.scopes.isAccessible) {
161
+ if (scope &&
162
+ resource.properties.filters &&
163
+ resource.properties.filters.scopes &&
164
+ resource.properties.filters.scopes.isAccessible) {
150
165
  if (resource.properties.filters.scopes.manual) {
151
166
  filter = yield resource.properties.filters.scopes.manual.handler(filter, scope);
152
167
  }
@@ -171,7 +186,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
171
186
  records = yield repository.findMany({
172
187
  sort: sortQuery,
173
188
  filter,
174
- populate: modifiedResource.properties.populatedString
189
+ populate: modifiedResource.properties.populatedString,
175
190
  });
176
191
  }
177
192
  else {
@@ -179,7 +194,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
179
194
  sort: sortQuery,
180
195
  filter,
181
196
  paginateParams: paginateParams,
182
- populate: modifiedResource.properties.populatedString
197
+ populate: modifiedResource.properties.populatedString,
183
198
  });
184
199
  records = page.records;
185
200
  pageInfo = page.pageInfo;
@@ -202,10 +217,10 @@ let DashboardController = DashboardController_1 = class DashboardController {
202
217
  if (crudOperations && crudOperations.index && crudOperations.index.after) {
203
218
  documents = yield crudOperations.index.after(req, documents, currentUser);
204
219
  }
205
- return ResponseUtils_1.default.send(res, 200, 'OK', {
220
+ return ResponseUtils_1.default.send(res, 200, "OK", {
206
221
  records: documents,
207
222
  pageInfo,
208
- //options: modifiedResource
223
+ //options: modifiedResource
209
224
  });
210
225
  });
211
226
  }
@@ -219,12 +234,14 @@ let DashboardController = DashboardController_1 = class DashboardController {
219
234
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
220
235
  const currentUser = req.user;
221
236
  if (!resource) {
222
- return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
237
+ return ResponseUtils_1.default.notFound(res, "Resource not found", []);
223
238
  }
224
239
  if (!currentUser) {
225
240
  return ResponseUtils_1.default.unauthorized(res);
226
241
  }
227
- const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
242
+ const permissionCheck = resource.properties.isAllowed
243
+ ? yield resource.properties.isAllowed(currentUser)
244
+ : true;
228
245
  if (!permissionCheck) {
229
246
  return ResponseUtils_1.default.forbidden(res);
230
247
  }
@@ -237,7 +254,9 @@ let DashboardController = DashboardController_1 = class DashboardController {
237
254
  var recordParams = req.body;
238
255
  recordParams = LocalizedStringHelper_1.default.mapLocalizableString(recordParams, resource);
239
256
  const crudOperations = resource.properties.crudOperations;
240
- if (crudOperations && crudOperations.create && crudOperations.create.before) {
257
+ if (crudOperations &&
258
+ crudOperations.create &&
259
+ crudOperations.create.before) {
241
260
  recordParams = yield crudOperations.create.before(req, recordParams, currentUser);
242
261
  }
243
262
  var record;
@@ -251,13 +270,15 @@ let DashboardController = DashboardController_1 = class DashboardController {
251
270
  record = yield repository.save(recordParams);
252
271
  }
253
272
  if (!record.isValid() || !record.document) {
254
- return ResponseUtils_1.default.unprocessable(res, 'Invalid Data', record.getErrors());
273
+ return ResponseUtils_1.default.unprocessable(res, "Invalid Data", record.getErrors());
255
274
  }
256
- if (crudOperations && crudOperations.create && crudOperations.create.after) {
275
+ if (crudOperations &&
276
+ crudOperations.create &&
277
+ crudOperations.create.after) {
257
278
  record = yield crudOperations.create.after(req, record, currentUser, recordParams);
258
279
  }
259
280
  return ResponseUtils_1.default.created(res, {
260
- record
281
+ record,
261
282
  });
262
283
  });
263
284
  }
@@ -270,14 +291,16 @@ let DashboardController = DashboardController_1 = class DashboardController {
270
291
  const modelName = req.params.resource;
271
292
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
272
293
  if (!resource) {
273
- return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
294
+ return ResponseUtils_1.default.notFound(res, "Resource not found", []);
274
295
  }
275
296
  var recordParams = req.body;
276
297
  const currentUser = req.user;
277
298
  if (!currentUser) {
278
299
  return ResponseUtils_1.default.unauthorized(res);
279
300
  }
280
- const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
301
+ const permissionCheck = resource.properties.isAllowed
302
+ ? yield resource.properties.isAllowed(currentUser)
303
+ : true;
281
304
  if (!permissionCheck) {
282
305
  return ResponseUtils_1.default.forbidden(res);
283
306
  }
@@ -290,24 +313,28 @@ let DashboardController = DashboardController_1 = class DashboardController {
290
313
  const recordId = req.params.id;
291
314
  var record = yield repository.findById(recordId);
292
315
  if (!record) {
293
- return ResponseUtils_1.default.send(res, 404, 'record Not Found');
316
+ return ResponseUtils_1.default.send(res, 404, "record Not Found");
294
317
  }
295
318
  const crudOperations = resource.properties.crudOperations;
296
- if (crudOperations && crudOperations.update && crudOperations.update.before) {
319
+ if (crudOperations &&
320
+ crudOperations.update &&
321
+ crudOperations.update.before) {
297
322
  recordParams = yield crudOperations.update.before(req, recordParams, currentUser);
298
323
  }
299
324
  var recordSaveResult = yield repository.update(record, recordParams);
300
325
  if (!recordSaveResult.isValid()) {
301
- return ResponseUtils_1.default.unprocessable(res, 'Invalid Data', recordSaveResult.getErrors());
326
+ return ResponseUtils_1.default.unprocessable(res, "Invalid Data", recordSaveResult.getErrors());
302
327
  }
303
328
  // if (resource.properties.modelName === ModelNames.Settings) {
304
329
  // await AppSettings.run()
305
330
  // }
306
- if (crudOperations && crudOperations.update && crudOperations.update.after) {
331
+ if (crudOperations &&
332
+ crudOperations.update &&
333
+ crudOperations.update.after) {
307
334
  recordSaveResult = yield crudOperations.update.after(req, recordSaveResult, recordParams, currentUser);
308
335
  }
309
336
  return ResponseUtils_1.default.ok(res, {
310
- record: recordSaveResult
337
+ record: recordSaveResult,
311
338
  });
312
339
  });
313
340
  }
@@ -322,25 +349,27 @@ let DashboardController = DashboardController_1 = class DashboardController {
322
349
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
323
350
  const currentUser = req.user;
324
351
  if (!resource) {
325
- return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
352
+ return ResponseUtils_1.default.notFound(res, "Resource not found", []);
326
353
  }
327
354
  if (!currentUser) {
328
355
  return ResponseUtils_1.default.unauthorized(res);
329
356
  }
330
- const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
357
+ const permissionCheck = resource.properties.isAllowed
358
+ ? yield resource.properties.isAllowed(currentUser)
359
+ : true;
331
360
  if (!permissionCheck) {
332
361
  return ResponseUtils_1.default.forbidden(res);
333
362
  }
334
363
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
335
- const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser);
364
+ const modifiedResource = ResourceGenerator_1.default.generate(resource, currentUser, undefined, this.modelConfigurations);
336
365
  var record = yield repository.findOne({
337
366
  filter: {
338
- _id: recordId
367
+ _id: recordId,
339
368
  },
340
- populate: modifiedResource.properties.populatedString
369
+ populate: modifiedResource.properties.populatedString,
341
370
  });
342
371
  if (!record) {
343
- return ResponseUtils_1.default.send(res, 404, 'record not found');
372
+ return ResponseUtils_1.default.send(res, 404, "record not found");
344
373
  }
345
374
  record = record.toObject();
346
375
  //record = await this.getExtras(record._id.toString(), record, this.getExtraRepository())
@@ -363,13 +392,15 @@ let DashboardController = DashboardController_1 = class DashboardController {
363
392
  const recordIds = req.body;
364
393
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
365
394
  if (!resource) {
366
- return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
395
+ return ResponseUtils_1.default.notFound(res, "Resource not found", []);
367
396
  }
368
397
  const currentUser = req.user;
369
398
  if (!currentUser) {
370
399
  return ResponseUtils_1.default.unauthorized(res);
371
400
  }
372
- const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
401
+ const permissionCheck = resource.properties.isAllowed
402
+ ? yield resource.properties.isAllowed(currentUser)
403
+ : true;
373
404
  if (!permissionCheck) {
374
405
  return ResponseUtils_1.default.forbidden(res);
375
406
  }
@@ -387,7 +418,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
387
418
  }
388
419
  yield repository.remove({ _id: record._id });
389
420
  }
390
- return ResponseUtils_1.default.send(res, 200, 'OK');
421
+ return ResponseUtils_1.default.send(res, 200, "OK");
391
422
  });
392
423
  }
393
424
  delete(req, res) {
@@ -400,13 +431,15 @@ let DashboardController = DashboardController_1 = class DashboardController {
400
431
  const recordId = req.params.id;
401
432
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
402
433
  if (!resource) {
403
- return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
434
+ return ResponseUtils_1.default.notFound(res, "Resource not found", []);
404
435
  }
405
436
  const currentUser = req.user;
406
437
  if (!currentUser) {
407
438
  return ResponseUtils_1.default.unauthorized(res);
408
439
  }
409
- const permissionCheck = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
440
+ const permissionCheck = resource.properties.isAllowed
441
+ ? yield resource.properties.isAllowed(currentUser)
442
+ : true;
410
443
  if (!permissionCheck) {
411
444
  return ResponseUtils_1.default.forbidden(res);
412
445
  }
@@ -418,10 +451,10 @@ let DashboardController = DashboardController_1 = class DashboardController {
418
451
  const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
419
452
  const record = yield repository.findById(recordId);
420
453
  if (!record) {
421
- return ResponseUtils_1.default.send(res, 404, 'record Not Found');
454
+ return ResponseUtils_1.default.send(res, 404, "record Not Found");
422
455
  }
423
456
  yield repository.remove({ _id: record._id });
424
- return ResponseUtils_1.default.send(res, 200, 'OK');
457
+ return ResponseUtils_1.default.send(res, 200, "OK");
425
458
  });
426
459
  }
427
460
  };
@@ -432,32 +465,32 @@ __decorate([
432
465
  __param(1, (0, inversify_express_utils_1.response)())
433
466
  ], DashboardController.prototype, "validateRequest", null);
434
467
  __decorate([
435
- (0, inversify_express_utils_1.httpGet)('/'),
468
+ (0, inversify_express_utils_1.httpGet)("/"),
436
469
  __param(0, (0, inversify_express_utils_1.request)()),
437
470
  __param(1, (0, inversify_express_utils_1.response)())
438
471
  ], DashboardController.prototype, "index", null);
439
472
  __decorate([
440
- (0, inversify_express_utils_1.httpPost)('/'),
473
+ (0, inversify_express_utils_1.httpPost)("/"),
441
474
  __param(0, (0, inversify_express_utils_1.request)()),
442
475
  __param(1, (0, inversify_express_utils_1.response)())
443
476
  ], DashboardController.prototype, "create", null);
444
477
  __decorate([
445
- (0, inversify_express_utils_1.httpPatch)('/:id'),
478
+ (0, inversify_express_utils_1.httpPatch)("/:id"),
446
479
  __param(0, (0, inversify_express_utils_1.request)()),
447
480
  __param(1, (0, inversify_express_utils_1.response)())
448
481
  ], DashboardController.prototype, "update", null);
449
482
  __decorate([
450
- (0, inversify_express_utils_1.httpGet)('/:id'),
483
+ (0, inversify_express_utils_1.httpGet)("/:id"),
451
484
  __param(0, (0, inversify_express_utils_1.request)()),
452
485
  __param(1, (0, inversify_express_utils_1.response)())
453
486
  ], DashboardController.prototype, "show", null);
454
487
  __decorate([
455
- (0, inversify_express_utils_1.httpDelete)('/all'),
488
+ (0, inversify_express_utils_1.httpDelete)("/all"),
456
489
  __param(0, (0, inversify_express_utils_1.request)()),
457
490
  __param(1, (0, inversify_express_utils_1.response)())
458
491
  ], DashboardController.prototype, "deleteAll", null);
459
492
  __decorate([
460
- (0, inversify_express_utils_1.httpDelete)('/:id'),
493
+ (0, inversify_express_utils_1.httpDelete)("/:id"),
461
494
  __param(0, (0, inversify_express_utils_1.request)()),
462
495
  __param(1, (0, inversify_express_utils_1.response)())
463
496
  ], DashboardController.prototype, "delete", null);
@@ -465,6 +498,7 @@ DashboardController = DashboardController_1 = __decorate([
465
498
  (0, inversify_1.injectable)(),
466
499
  __param(0, (0, inversify_1.unmanaged)()),
467
500
  __param(1, (0, inversify_1.unmanaged)()),
468
- __param(2, (0, inversify_1.unmanaged)())
501
+ __param(2, (0, inversify_1.unmanaged)()),
502
+ __param(3, (0, inversify_1.unmanaged)())
469
503
  ], DashboardController);
470
504
  exports.default = DashboardController;
@@ -1,11 +1,13 @@
1
- import { Response } from 'express';
2
- import { IResourceFile } from '../types/IResourceFile';
3
- import { IRequest } from '../middlewares/isAuth';
4
- import { IConfiguartionFile } from '../types/IConfigurationFile';
1
+ import { Response } from "express";
2
+ import { IResourceFile } from "../types/IResourceFile";
3
+ import { IRequest } from "../middlewares/isAuth";
4
+ import { IConfiguartionFile } from "../types/IConfigurationFile";
5
+ import { IModelConfigurationDocument } from "../models/modelConfiguration/IModelConfigurations";
5
6
  export default class ResourceController {
6
7
  private resourceFiles;
7
8
  private configurations;
8
- constructor(resourceFiles: IResourceFile[], configurations: IConfiguartionFile | undefined);
9
+ private modelConfigurations?;
10
+ constructor(resourceFiles: IResourceFile[], configurations: IConfiguartionFile | undefined, modelConfigurations?: Map<string, IModelConfigurationDocument> | undefined);
9
11
  index(req: IRequest, res: Response): Promise<Response<any, Record<string, any>>>;
10
12
  getOne(req: IRequest, res: Response): Promise<Response<any, Record<string, any>>>;
11
13
  }
@@ -50,9 +50,10 @@ const StringUtils_1 = __importDefault(require("../utils/StringUtils"));
50
50
  const ResourceGenerator_1 = __importDefault(require("../helpers/ResourceGenerator"));
51
51
  const inversify_1 = require("inversify");
52
52
  let ResourceController = class ResourceController {
53
- constructor(resourceFiles, configurations) {
53
+ constructor(resourceFiles, configurations, modelConfigurations) {
54
54
  this.resourceFiles = resourceFiles;
55
55
  this.configurations = configurations;
56
+ this.modelConfigurations = modelConfigurations;
56
57
  }
57
58
  index(req, res) {
58
59
  return __awaiter(this, void 0, void 0, function* () {
@@ -64,10 +65,14 @@ let ResourceController = class ResourceController {
64
65
  }
65
66
  for (var i = 0; i < this.resourceFiles.length; i++) {
66
67
  const resource = this.resourceFiles[i];
67
- const isAllowed = resource.properties.isAllowed ? yield resource.properties.isAllowed(currentUser) : true;
68
- const isVisibile = resource.properties.isVisible ? yield resource.properties.isVisible(currentUser) : true;
68
+ const isAllowed = resource.properties.isAllowed
69
+ ? yield resource.properties.isAllowed(currentUser)
70
+ : true;
71
+ const isVisibile = resource.properties.isVisible
72
+ ? yield resource.properties.isVisible(currentUser)
73
+ : true;
69
74
  if (isAllowed) {
70
- const adaptedResource = ResourceGenerator_1.default.generate(resource, currentUser, this.configurations);
75
+ const adaptedResource = ResourceGenerator_1.default.generate(resource, currentUser, this.configurations, this.modelConfigurations);
71
76
  const modelName = StringUtils_1.default.lowerCaseFirstLetter(adaptedResource.properties.modelName);
72
77
  modifiedResource[modelName] = adaptedResource;
73
78
  if (isVisibile) {
@@ -81,37 +86,39 @@ let ResourceController = class ResourceController {
81
86
  }
82
87
  }
83
88
  }
84
- return ResponseUtils_1.default.send(res, 200, 'OK', {
85
- resources: modifiedResource
89
+ return ResponseUtils_1.default.send(res, 200, "OK", {
90
+ resources: modifiedResource,
86
91
  });
87
92
  });
88
93
  }
89
94
  getOne(req, res) {
90
95
  return __awaiter(this, void 0, void 0, function* () {
91
96
  const modelName = req.params.modelName;
92
- const resourceName = modelName + 'Resource';
93
- const resourceFilePath = '@pbb/materialUi/' + resourceName;
97
+ const resourceName = modelName + "Resource";
98
+ const resourceFilePath = "@pbb/materialUi/" + resourceName;
94
99
  const resource = yield Promise.resolve().then(() => __importStar(require(resourceFilePath)));
95
100
  const currentUser = req.user;
96
- return ResponseUtils_1.default.send(res, 200, 'OK', {
97
- options: ResourceGenerator_1.default.generate(resource[resourceName], currentUser)
101
+ console.log("Single Resource", this.modelConfigurations);
102
+ return ResponseUtils_1.default.send(res, 200, "OK", {
103
+ options: ResourceGenerator_1.default.generate(resource[resourceName], currentUser, this.configurations, this.modelConfigurations),
98
104
  });
99
105
  });
100
106
  }
101
107
  };
102
108
  __decorate([
103
- (0, inversify_express_utils_1.httpGet)('/'),
109
+ (0, inversify_express_utils_1.httpGet)("/"),
104
110
  __param(0, (0, inversify_express_utils_1.request)()),
105
111
  __param(1, (0, inversify_express_utils_1.response)())
106
112
  ], ResourceController.prototype, "index", null);
107
113
  __decorate([
108
- (0, inversify_express_utils_1.httpGet)('/:modelName'),
114
+ (0, inversify_express_utils_1.httpGet)("/:modelName"),
109
115
  __param(0, (0, inversify_express_utils_1.request)()),
110
116
  __param(1, (0, inversify_express_utils_1.response)())
111
117
  ], ResourceController.prototype, "getOne", null);
112
118
  ResourceController = __decorate([
113
119
  (0, inversify_1.injectable)(),
114
120
  __param(0, (0, inversify_1.unmanaged)()),
115
- __param(1, (0, inversify_1.unmanaged)())
121
+ __param(1, (0, inversify_1.unmanaged)()),
122
+ __param(2, (0, inversify_1.unmanaged)())
116
123
  ], ResourceController);
117
124
  exports.default = ResourceController;
@@ -1,6 +1,7 @@
1
1
  import { Document } from "mongoose";
2
2
  import { IResourceFile } from "../types/IResourceFile";
3
3
  import { IConfiguartionFile } from "../types/IConfigurationFile";
4
+ import { IModelConfigurationDocument } from "../models/modelConfiguration/IModelConfigurations";
4
5
  export default class ResourceGenerator {
5
- static generate(resource: IResourceFile, currentUser: Document, configurations?: IConfiguartionFile): any;
6
+ static generate(resource: IResourceFile, currentUser: Document, configurations?: IConfiguartionFile, modelConfigurations?: Map<string, IModelConfigurationDocument>): any;
6
7
  }
@@ -32,24 +32,27 @@ const SchemaGenerator_1 = __importDefault(require("./SchemaGenerator"));
32
32
  const ResourceHelper_1 = __importDefault(require("./ResourceHelper"));
33
33
  const ActionsGenerator_1 = __importDefault(require("./ActionsGenerator"));
34
34
  const SetupParent = {
35
- name: 'Setup',
36
- icon: 'PermDataSetting',
35
+ name: "Setup",
36
+ icon: "PermDataSetting",
37
37
  //value: __({phrase: "Setup", locale: i18n.getLocale()})
38
38
  };
39
39
  class ResourceGenerator {
40
- static generate(resource, currentUser, configurations) {
40
+ static generate(resource, currentUser, configurations, modelConfigurations) {
41
41
  var _a, _b, _c, _d, _e, _f, _g;
42
42
  const SetupParent = {
43
- name: 'Setup',
44
- icon: 'PermDataSetting',
45
- value: (0, i18n_1.__)({ phrase: "Setup", locale: i18n_1.default.getLocale() })
43
+ name: "Setup",
44
+ icon: "PermDataSetting",
45
+ value: (0, i18n_1.__)({ phrase: "Setup", locale: i18n_1.default.getLocale() }),
46
46
  };
47
47
  const modelName = resource.properties.modelName;
48
+ const modelConfiguration = modelConfigurations === null || modelConfigurations === void 0 ? void 0 : modelConfigurations.get(modelName);
48
49
  const modifiedResource = JSON.parse(JSON.stringify(resource));
49
50
  const schema = resource.properties.resource.schema.paths;
50
- const title = ResourceHelper_1.default.getSchemaTitle(schema, resource);
51
+ const title = ResourceHelper_1.default.getSchemaTitle(schema, resource, modelConfiguration);
51
52
  const recordFields = ResourceHelper_1.default.manageFields(schema, title, resource.properties.hiddenProperties);
52
- const modelCheck = resource.properties.model ? JSON.parse(JSON.stringify(resource.properties.model)) : undefined;
53
+ const modelCheck = resource.properties.model
54
+ ? JSON.parse(JSON.stringify(resource.properties.model))
55
+ : undefined;
53
56
  const actionsCheck = resource.properties.actions;
54
57
  const modelAndPopulatedString = SchemaGenerator_1.default.generateSchema(schema, modelCheck, modelName, resource);
55
58
  modifiedResource.properties.model = modelAndPopulatedString[0];
@@ -67,45 +70,87 @@ class ResourceGenerator {
67
70
  modifiedResource.properties.parent = {
68
71
  name: resource.properties.parent.name,
69
72
  icon: resource.properties.parent.icon,
70
- value: (0, i18n_1.__)({ phrase: resource.properties.parent.name, locale: i18n_1.default.getLocale() })
73
+ value: (0, i18n_1.__)({
74
+ phrase: resource.properties.parent.name,
75
+ locale: i18n_1.default.getLocale(),
76
+ }),
71
77
  };
72
78
  }
73
79
  if (!resource.properties.name) {
74
- modifiedResource.properties.name = (0, i18n_1.__)({ phrase: StringUtils_1.default.convertCamelCaseToWord(modelName), locale: i18n_1.default.getLocale() });
80
+ modifiedResource.properties.name = (0, i18n_1.__)({
81
+ phrase: StringUtils_1.default.convertCamelCaseToWord(modelName),
82
+ locale: i18n_1.default.getLocale(),
83
+ });
75
84
  }
76
85
  if (!resource.showProperties) {
77
- modifiedResource.showProperties = modifiedShowProperties;
86
+ modifiedResource.showProperties =
87
+ modelConfiguration && modelConfiguration.showProperties
88
+ ? modelConfiguration.showProperties
89
+ : modifiedShowProperties;
78
90
  }
79
91
  if (!resource.filterProperties) {
80
- modifiedResource.filterProperties = modifiedFilterProperties;
92
+ modifiedResource.filterProperties =
93
+ modelConfiguration && modelConfiguration.filterProperties
94
+ ? modelConfiguration.filterProperties
95
+ : modifiedFilterProperties;
81
96
  }
82
97
  if (!resource.quickFilterProperties) {
83
- modifiedResource.quickFilterProperties = [];
98
+ modifiedResource.quickFilterProperties =
99
+ modelConfiguration && modelConfiguration.quickFilterProperties
100
+ ? modelConfiguration.quickFilterProperties
101
+ : [];
84
102
  }
85
103
  if (!resource.listProperties) {
86
- modifiedResource.listProperties = ResourceHelper_1.default.exchangeFirstFieldWithTitle(JSON.parse(JSON.stringify(modifiedListProperties)), title);
104
+ modifiedResource.listProperties =
105
+ modelConfiguration && modelConfiguration.listProperties
106
+ ? modelConfiguration.listProperties
107
+ : ResourceHelper_1.default.exchangeFirstFieldWithTitle(JSON.parse(JSON.stringify(modifiedListProperties)), title);
87
108
  }
88
109
  if (!resource.formProperties) {
89
- modifiedResource.formProperties = ResourceHelper_1.default.removeUnWantedFieldsFromCreateOrUpdate(JSON.parse(JSON.stringify(modifiedFormProperties)));
110
+ modifiedResource.formProperties =
111
+ ResourceHelper_1.default.removeUnWantedFieldsFromCreateOrUpdate(JSON.parse(JSON.stringify(modifiedFormProperties)));
90
112
  }
91
113
  modifiedResource.properties.title = title;
92
114
  if (!resource.properties.defaultOrderBy) {
93
- modifiedResource.properties.defaultOrderBy = title;
115
+ modifiedResource.properties.defaultOrderBy =
116
+ modelConfiguration && modelConfiguration.defaultOrderBy
117
+ ? modelConfiguration.defaultOrderBy
118
+ : title;
94
119
  }
95
120
  if (!resource.properties.defaultOrder) {
96
- modifiedResource.properties.defaultOrder = 'asc';
121
+ modifiedResource.properties.defaultOrder =
122
+ modelConfiguration && modelConfiguration.defaultOrder
123
+ ? modelConfiguration.defaultOrder
124
+ : "asc";
97
125
  }
98
126
  if (!resource.properties.defaultrowsPerPage) {
99
- modifiedResource.properties.defaultrowsPerPage = configurations && configurations.defaultRowsPerPage ? configurations.defaultRowsPerPage : 10;
127
+ modifiedResource.properties.defaultrowsPerPage =
128
+ modelConfiguration && modelConfiguration.defaultrowsPerPage
129
+ ? modelConfiguration.defaultrowsPerPage
130
+ : configurations && configurations.defaultRowsPerPage
131
+ ? configurations.defaultRowsPerPage
132
+ : 10;
100
133
  }
101
- modifiedResource.listProperties = ResourceHelper_1.default.prepareProperties(resource.listProperties ? resource.listProperties : modifiedResource.listProperties, modelName, modifiedResource.properties.model, resource);
102
- modifiedResource.showProperties = ResourceHelper_1.default.prepareProperties(resource.showProperties ? resource.showProperties : modifiedResource.showProperties, modelName, modifiedResource.properties.model, resource);
134
+ modifiedResource.listProperties = ResourceHelper_1.default.prepareProperties(resource.listProperties
135
+ ? resource.listProperties
136
+ : modifiedResource.listProperties, modelName, modifiedResource.properties.model, resource);
137
+ modifiedResource.showProperties = ResourceHelper_1.default.prepareProperties(resource.showProperties
138
+ ? resource.showProperties
139
+ : modifiedResource.showProperties, modelName, modifiedResource.properties.model, resource);
103
140
  modifiedResource.filterProperties = ResourceHelper_1.default.prepareFilterProperties(modifiedResource.filterProperties, modifiedResource.properties.model);
104
- modifiedResource.quickFilterProperties = ResourceHelper_1.default.prepareFilterProperties(modifiedResource.quickFilterProperties, modifiedResource.properties.model);
105
- modifiedResource.properties.filters = ResourceHelper_1.default.getFilters(resource.properties.filters ? JSON.parse(JSON.stringify(resource.properties.filters)) : undefined);
106
- if (modifiedResource.properties.filters && modifiedResource.properties.filters.scopes && modifiedResource.properties.filters.scopes.isAccessible) {
107
- 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;
108
- modifiedResource.properties.filters.scopes.options = ResourceHelper_1.default.setScopeFilterOptions(modelName, options);
141
+ modifiedResource.quickFilterProperties =
142
+ ResourceHelper_1.default.prepareFilterProperties(modifiedResource.quickFilterProperties, modifiedResource.properties.model);
143
+ modifiedResource.properties.filters = ResourceHelper_1.default.getFilters(resource.properties.filters
144
+ ? JSON.parse(JSON.stringify(resource.properties.filters))
145
+ : undefined);
146
+ if (modifiedResource.properties.filters &&
147
+ modifiedResource.properties.filters.scopes &&
148
+ modifiedResource.properties.filters.scopes.isAccessible) {
149
+ const options = ((_b = (_a = resource.properties.filters) === null || _a === void 0 ? void 0 : _a.scopes) === null || _b === void 0 ? void 0 : _b.auto)
150
+ ? (_d = (_c = resource.properties.filters) === null || _c === void 0 ? void 0 : _c.scopes) === null || _d === void 0 ? void 0 : _d.auto.options
151
+ : (_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;
152
+ modifiedResource.properties.filters.scopes.options =
153
+ ResourceHelper_1.default.setScopeFilterOptions(modelName, options);
109
154
  }
110
155
  const actions = ActionsGenerator_1.default.generateActions(actionsCheck, resource, currentUser);
111
156
  modifiedResource.properties.actions = actions;
@@ -1,6 +1,7 @@
1
1
  import { IResourceFile } from "../types/IResourceFile";
2
+ import { IModelConfigurationDocument } from "../models/modelConfiguration/IModelConfigurations";
2
3
  export default class ResourcesHelper {
3
- static getSchemaTitle(schema: any, resource: any): any;
4
+ static getSchemaTitle(schema: any, resource: any, modelConfiguration: IModelConfigurationDocument | undefined): any;
4
5
  static prepareProperties(properties: string[], modelName: string, model: any, resource: IResourceFile): {}[];
5
6
  private static getPropertyObject;
6
7
  private static getRawName;
@@ -41,10 +41,13 @@ const i18n_1 = __importStar(require("i18n"));
41
41
  const Repository_1 = __importDefault(require("../repositories/Repository"));
42
42
  var pluralize = require('pluralize');
43
43
  class ResourcesHelper {
44
- static getSchemaTitle(schema, resource) {
44
+ static getSchemaTitle(schema, resource, modelConfiguration) {
45
45
  if (resource.properties.title) {
46
46
  return resource.properties.title;
47
47
  }
48
+ if (modelConfiguration && modelConfiguration.title) {
49
+ return modelConfiguration.title;
50
+ }
48
51
  return this.getTitle(schema);
49
52
  }
50
53
  static prepareProperties(properties, modelName, model, resource) {
@@ -0,0 +1,21 @@
1
+ import { Document, Model, Types } from 'mongoose';
2
+ import { RowArrangeType } from './ModelConfiguration';
3
+ export interface IModelConfigurationProps {
4
+ _id?: Types.ObjectId;
5
+ modelName: string;
6
+ title?: string;
7
+ defaultOrderBy?: string;
8
+ defaultOrder?: RowArrangeType;
9
+ defaultrowsPerPage?: number;
10
+ listProperties?: string[];
11
+ showProperties?: string[];
12
+ filterProperties?: string[];
13
+ quickFilterProperties?: string[];
14
+ }
15
+ export interface IModelConfigurationDocument extends IModelConfigurationProps, Document {
16
+ _id: Types.ObjectId;
17
+ createdAt: Date;
18
+ updatedAt: Date;
19
+ }
20
+ export default interface IModelConfigurationModel extends Model<IModelConfigurationDocument> {
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { Schema, SchemaOptions } from "mongoose";
2
+ export declare enum RowArrangeType {
3
+ ASCENDING = "asc",
4
+ DESCENDING = "desc"
5
+ }
6
+ export declare function getModelConfiguartionSchema(schemaOptions: SchemaOptions): Schema;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModelConfiguartionSchema = exports.RowArrangeType = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ var RowArrangeType;
6
+ (function (RowArrangeType) {
7
+ RowArrangeType["ASCENDING"] = "asc";
8
+ RowArrangeType["DESCENDING"] = "desc";
9
+ })(RowArrangeType = exports.RowArrangeType || (exports.RowArrangeType = {}));
10
+ function getModelConfiguartionSchema(schemaOptions) {
11
+ return new mongoose_1.Schema({
12
+ modelName: {
13
+ type: String,
14
+ required: true,
15
+ },
16
+ title: {
17
+ type: String,
18
+ required: false,
19
+ },
20
+ defaultOrderBy: {
21
+ type: String,
22
+ required: false,
23
+ },
24
+ defaultOrder: {
25
+ type: String,
26
+ enum: Object.values(RowArrangeType),
27
+ default: RowArrangeType.DESCENDING,
28
+ required: false,
29
+ },
30
+ defaultrowsPerPage: {
31
+ type: Number,
32
+ required: false,
33
+ },
34
+ listProperties: [
35
+ {
36
+ type: String,
37
+ required: false,
38
+ },
39
+ ],
40
+ showProperties: [
41
+ {
42
+ type: String,
43
+ required: false,
44
+ },
45
+ ],
46
+ filterProperties: [
47
+ {
48
+ type: String,
49
+ required: false,
50
+ },
51
+ ],
52
+ quickFilterProperties: [
53
+ {
54
+ type: String,
55
+ required: false,
56
+ },
57
+ ],
58
+ }, schemaOptions);
59
+ }
60
+ exports.getModelConfiguartionSchema = getModelConfiguartionSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",