identity-admin 1.4.4 → 1.6.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 (97) hide show
  1. package/README.md +126 -126
  2. package/lib/Dashboard.d.ts +14 -14
  3. package/lib/Dashboard.js +95 -88
  4. package/lib/container/helpers/HelperInversify.d.ts +6 -6
  5. package/lib/container/helpers/HelperInversify.js +10 -10
  6. package/lib/container/helpers/HelperTypes.d.ts +5 -5
  7. package/lib/container/helpers/HelperTypes.js +7 -7
  8. package/lib/container/index.d.ts +1 -1
  9. package/lib/container/index.js +14 -14
  10. package/lib/container/repositories/RepositoryInversify.d.ts +4 -4
  11. package/lib/container/repositories/RepositoryInversify.js +13 -13
  12. package/lib/container/repositories/RepositoryTypes.d.ts +4 -4
  13. package/lib/container/repositories/RepositoryTypes.js +6 -6
  14. package/lib/container/types.d.ts +8 -8
  15. package/lib/container/types.js +9 -9
  16. package/lib/controllers/ActionController.d.ts +8 -8
  17. package/lib/controllers/ActionController.js +79 -79
  18. package/lib/controllers/DashboardController.d.ts +36 -36
  19. package/lib/controllers/DashboardController.js +349 -335
  20. package/lib/controllers/ResourceController.d.ts +11 -9
  21. package/lib/controllers/ResourceController.js +109 -104
  22. package/lib/helpers/ActionsGenerator.d.ts +9 -9
  23. package/lib/helpers/ActionsGenerator.js +101 -77
  24. package/lib/helpers/FiltersHelper.d.ts +7 -0
  25. package/lib/helpers/FiltersHelper.js +64 -0
  26. package/lib/helpers/LocalesHelper.d.ts +4 -4
  27. package/lib/helpers/LocalesHelper.js +73 -73
  28. package/lib/helpers/ResourceGenerator.d.ts +4 -4
  29. package/lib/helpers/ResourceGenerator.js +110 -68
  30. package/lib/helpers/ResourceHelper.d.ts +23 -22
  31. package/lib/helpers/ResourceHelper.js +305 -286
  32. package/lib/helpers/SchemaGenerator.d.ts +5 -5
  33. package/lib/helpers/SchemaGenerator.js +92 -87
  34. package/lib/helpers/SchemaHelper.d.ts +5 -5
  35. package/lib/helpers/SchemaHelper.js +21 -21
  36. package/lib/locales/ar.json +1 -0
  37. package/lib/locales/en.json +50 -10
  38. package/lib/middlewares/isAuth.d.ts +13 -13
  39. package/lib/middlewares/isAuth.js +43 -43
  40. package/lib/models/ModelNames.d.ts +4 -4
  41. package/lib/models/ModelNames.js +7 -7
  42. package/lib/models/request-log/IRequestLog.d.ts +22 -22
  43. package/lib/models/request-log/IRequestLog.js +2 -2
  44. package/lib/models/request-log/RequestLog.d.ts +3 -3
  45. package/lib/models/request-log/RequestLog.js +51 -51
  46. package/lib/repositories/DashboardRepository.d.ts +5 -5
  47. package/lib/repositories/DashboardRepository.js +12 -12
  48. package/lib/repositories/Repository.d.ts +68 -68
  49. package/lib/repositories/Repository.js +212 -212
  50. package/lib/repositories/RequestLogRepository.d.ts +10 -10
  51. package/lib/repositories/RequestLogRepository.js +54 -54
  52. package/lib/repositories/SaveResult.d.ts +14 -14
  53. package/lib/repositories/SaveResult.js +18 -18
  54. package/lib/router/index.d.ts +8 -8
  55. package/lib/router/index.js +97 -97
  56. package/lib/types/DashbordConfig.d.ts +21 -19
  57. package/lib/types/DashbordConfig.js +2 -2
  58. package/lib/types/IConfigurationFile.d.ts +5 -0
  59. package/lib/types/IConfigurationFile.js +2 -0
  60. package/lib/types/IResourceFile.d.ts +145 -125
  61. package/lib/types/IResourceFile.js +2 -2
  62. package/lib/types/helpers.d.ts +28 -15
  63. package/lib/types/helpers.js +35 -21
  64. package/lib/utils/ResourceUtils.d.ts +2 -2
  65. package/lib/utils/ResourceUtils.js +7 -7
  66. package/lib/utils/ResponseUtils.d.ts +10 -10
  67. package/lib/utils/ResponseUtils.js +38 -38
  68. package/lib/utils/StringUtils.d.ts +9 -9
  69. package/lib/utils/StringUtils.js +46 -46
  70. package/lib/view/asset-manifest.json +13 -13
  71. package/lib/view/assets/icons/delete_icon.svg +3 -3
  72. package/lib/view/assets/icons/flags/ic_flag_cn.svg +9 -9
  73. package/lib/view/assets/icons/flags/ic_flag_sa.svg +9 -9
  74. package/lib/view/assets/icons/flags/ic_flag_vn.svg +9 -9
  75. package/lib/view/assets/icons/info_icon.svg +3 -3
  76. package/lib/view/assets/icons/navbar/ic_banking.svg +5 -5
  77. package/lib/view/assets/icons/navbar/ic_invoice.svg +4 -4
  78. package/lib/view/assets/icons/navbar/ic_kanban.svg +7 -7
  79. package/lib/view/assets/icons/navbar/ic_menu_item.svg +8 -8
  80. package/lib/view/assets/icons/small_info_icon.svg +3 -3
  81. package/lib/view/assets/illustrations/Group 16.svg +4 -4
  82. package/lib/view/assets/illustrations/logo.svg +5 -5
  83. package/lib/view/favicon/browserconfig.xml +9 -9
  84. package/lib/view/favicon/safari-pinned-tab.svg +182 -182
  85. package/lib/view/favicon/site.webmanifest +19 -19
  86. package/lib/view/fonts/index.css +18 -18
  87. package/lib/view/index.html +1 -1
  88. package/lib/view/manifest.json +20 -20
  89. package/lib/view/robots.txt +3 -3
  90. package/lib/view/static/js/{148.b6f24fc9.chunk.js → 148.b05fe2c8.chunk.js} +1 -1
  91. package/lib/view/static/js/{705.b2b55cc3.chunk.js → 705.f86db82e.chunk.js} +1 -1
  92. package/lib/view/static/js/802.3f287a2c.chunk.js +1 -0
  93. package/lib/view/static/js/main.da8f09ec.js +2 -0
  94. package/lib/view/static/js/{main.bc5ec798.js.LICENSE.txt → main.da8f09ec.js.LICENSE.txt} +225 -223
  95. package/package.json +51 -51
  96. package/lib/view/static/js/939.f35326c5.chunk.js +0 -1
  97. package/lib/view/static/js/main.bc5ec798.js +0 -2
@@ -1,286 +1,305 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const helpers_1 = require("../types/helpers");
16
- const StringUtils_1 = __importDefault(require("../utils/StringUtils"));
17
- const i18n_1 = require("i18n");
18
- const Repository_1 = __importDefault(require("../repositories/Repository"));
19
- var pluralize = require('pluralize');
20
- class ResourcesHelper {
21
- static getSchemaTitle(schema, resource) {
22
- if (resource.properties.title) {
23
- return resource.properties.title;
24
- }
25
- return this.getTitle(schema);
26
- }
27
- static prepareProperties(properties, modelName, model, resource) {
28
- var preparedProperties = [];
29
- properties.forEach(key => {
30
- if (model[key]) {
31
- const refCheck = model[key].type === 'ref';
32
- var path = undefined;
33
- if (refCheck) {
34
- path = model[key].path;
35
- }
36
- const translation = this.checkResourceTranslation(resource, key);
37
- const propertyObject = {
38
- key,
39
- value: translation ? translation : StringUtils_1.default.checkRefId(key) ? StringUtils_1.default.convertCamelCaseToWord(key.slice(0, -2)) : StringUtils_1.default.convertCamelCaseToWord(key),
40
- path: path
41
- };
42
- preparedProperties.push(propertyObject);
43
- }
44
- });
45
- return preparedProperties;
46
- }
47
- static getFieldType(schemaField) {
48
- if (schemaField.instance === 'password') {
49
- return 'password';
50
- }
51
- if (schemaField.instance === 'Embedded') {
52
- return 'nestedSchema';
53
- }
54
- if (schemaField.options.ref) {
55
- return 'ref';
56
- }
57
- else if (schemaField.enumValues && schemaField.enumValues.length !== 0) {
58
- return 'enum';
59
- }
60
- else {
61
- return schemaField.instance;
62
- }
63
- }
64
- static checkResourceTranslation(resource, key) {
65
- var translation = undefined;
66
- if (!resource.properties.keysTranslations || !resource.properties.keysTranslations[key]) {
67
- return translation;
68
- }
69
- translation = (0, i18n_1.__)(resource.properties.keysTranslations[key]);
70
- return translation;
71
- }
72
- static checkActionTranslation(resource, action) {
73
- var translation = undefined;
74
- if (!resource.properties.actionsTranslations || !resource.properties.actionsTranslations[action]) {
75
- return translation;
76
- }
77
- translation = (0, i18n_1.__)(resource.properties.actionsTranslations[action]);
78
- return translation;
79
- }
80
- static setScopeFilterOptions(modelName, options) {
81
- var arrayOfOptions = [];
82
- options.forEach((key) => {
83
- const valueOfOption = StringUtils_1.default.lowerCaseFirstLetter(modelName) + '_filter_scope_' + key;
84
- const optionObject = {
85
- key,
86
- value: (0, i18n_1.__)(valueOfOption)
87
- };
88
- arrayOfOptions.push(optionObject);
89
- });
90
- return arrayOfOptions;
91
- }
92
- static getFilters(filters) {
93
- var filterObject = {
94
- scopes: {},
95
- searchBar: {}
96
- };
97
- if (!filters || Object.keys(filters).length === 0) {
98
- filterObject = {
99
- scopes: {
100
- isAccessible: false
101
- },
102
- searchBar: {
103
- isAccessible: true
104
- }
105
- };
106
- return filterObject;
107
- }
108
- if (!filters.searchBar || !filters.searchBar.hasOwnProperty('isAccessible')) {
109
- filterObject.searchBar = {
110
- isAccessible: true
111
- };
112
- }
113
- else {
114
- filterObject.searchBar = filters.searchBar;
115
- }
116
- if (!filters.scopes || !filters.scopes.hasOwnProperty('isAccessible')) {
117
- filterObject.scopes = {
118
- isAccessible: false
119
- };
120
- }
121
- else {
122
- filterObject.scopes = filters.scopes;
123
- }
124
- return filterObject;
125
- }
126
- static addExtraFields(showProperties, model, record, filterBy, resource) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- for (var i = 0; i < showProperties.length; i++) {
129
- // if (!model.hasOwnProperty(showProperties[i].key)) {
130
- // const modelName = pluralize.singular(showProperties[i].key)
131
- // const repository: any = this.getResourceSymbol(modelName)
132
- // filterBy = filterBy + "Id"
133
- // const filterQuery: {[key:string]: any} = {}
134
- // filterQuery[filterBy] = record._id
135
- // const extraRecords = await repository.findMany({
136
- // filter: filterQuery
137
- // });
138
- // record[showProperties[i].key] = extraRecords
139
- // }
140
- const key = showProperties[i].key;
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 = 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);
155
- filterBy = filterBy + "Id";
156
- const filterQuery = {};
157
- filterQuery[filterBy] = record._id;
158
- const extraRecords = yield repository.findMany({
159
- filter: filterQuery
160
- });
161
- record[showProperties[i].key] = extraRecords;
162
- }
163
- }
164
- ;
165
- return record;
166
- });
167
- }
168
- // public static getResourceRepository(resourceName: string) {
169
- // const resource = StringUtils.upperCaseFirstLetter(resourceName);
170
- // const repositorySymbol = Symbol.for(`I${resource}Repository`)
171
- // const repository = container.get(repositorySymbol)
172
- // return repository;
173
- // }
174
- static getTitle(schema) {
175
- if (schema['title']) {
176
- return 'title';
177
- }
178
- if (schema['name']) {
179
- return 'name';
180
- }
181
- if (schema['email']) {
182
- return 'email';
183
- }
184
- return '_id';
185
- }
186
- static exchangeFirstFieldWithTitle(arrayOfFields, title) {
187
- if (arrayOfFields[0] !== title) {
188
- for (var i = 1; i < arrayOfFields.length; i++) {
189
- const field = arrayOfFields[i];
190
- if (field === title) {
191
- const temp = arrayOfFields[0];
192
- arrayOfFields[0] = title;
193
- arrayOfFields[i] = temp;
194
- break;
195
- }
196
- }
197
- }
198
- return arrayOfFields;
199
- }
200
- static addVirtualFields(arrayOfFields, model) {
201
- var showProperties = JSON.parse(JSON.stringify(arrayOfFields));
202
- var listProperties = JSON.parse(JSON.stringify(arrayOfFields));
203
- var formProperties = JSON.parse(JSON.stringify(arrayOfFields));
204
- if (!model || !model.virtuals || !(Object.keys(model.virtuals))) {
205
- return [listProperties, showProperties, formProperties];
206
- }
207
- const virtualFields = model.virtuals;
208
- for (const extraField in virtualFields) {
209
- if (virtualFields[extraField].showIn) {
210
- switch (virtualFields[extraField].showIn) {
211
- case helpers_1.Virtuals.SHOW:
212
- showProperties.push(extraField);
213
- break;
214
- case helpers_1.Virtuals.LIST:
215
- listProperties.push(extraField);
216
- break;
217
- case helpers_1.Virtuals.FORM:
218
- formProperties.push(extraField);
219
- break;
220
- }
221
- }
222
- else {
223
- showProperties.push(extraField);
224
- listProperties.push(extraField);
225
- formProperties.push(extraField);
226
- }
227
- }
228
- return [listProperties, showProperties, formProperties];
229
- }
230
- static manageFields(schema, title, hiddenProperties) {
231
- var arrayOfFields = [];
232
- if (!hiddenProperties || !hiddenProperties.includes('_id')) {
233
- arrayOfFields.push('_id');
234
- }
235
- if (title !== '_id' && (!hiddenProperties || !hiddenProperties.includes(title))) {
236
- arrayOfFields.push(title);
237
- }
238
- const fields = Object.keys(schema);
239
- for (var i = 0; i < fields.length; i++) {
240
- const fieldKey = fields[i];
241
- if (hiddenProperties && hiddenProperties.includes(fieldKey)) {
242
- continue;
243
- }
244
- const unwantedField = this.checkUnwantedFields(fieldKey, title);
245
- if (unwantedField) {
246
- continue;
247
- }
248
- arrayOfFields.push(fieldKey);
249
- }
250
- return arrayOfFields;
251
- }
252
- static checkUnwantedFields(fieldKey, title) {
253
- if (fieldKey === '__v' || fieldKey === '_id' || fieldKey === title || fieldKey === 'salt' || fieldKey === 'hash' || fieldKey === 'forgotPasswordToken') {
254
- return true;
255
- }
256
- return false;
257
- }
258
- static getModelPath(modelName) {
259
- const modelPath = pluralize(StringUtils_1.default.lowerCaseFirstLetter(modelName));
260
- return modelPath;
261
- }
262
- static removeUnWantedFieldsFromCreateOrUpdate(arrayOfFields) {
263
- var modifiedArrayOfFields = [];
264
- arrayOfFields.forEach(field => {
265
- if (field !== '_id' && field !== 'createdAt' && field !== 'updatedAt') {
266
- modifiedArrayOfFields.push(field);
267
- }
268
- });
269
- return modifiedArrayOfFields;
270
- }
271
- // public static checkIndexBeforeHandler(resource: any) {
272
- // const crudOperations = resource.properties.crudOperations
273
- // if (crudOperations && crudOperations.index && crudOperations.index.before) {
274
- // return true
275
- // }
276
- // return false
277
- // }
278
- static checkCreateBeforeHandler(resource) {
279
- const crudOperations = resource.properties.crudOperations;
280
- if (crudOperations && crudOperations.create && crudOperations.create.before) {
281
- return true;
282
- }
283
- return false;
284
- }
285
- }
286
- exports.default = ResourcesHelper;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const helpers_1 = require("../types/helpers");
39
+ const StringUtils_1 = __importDefault(require("../utils/StringUtils"));
40
+ const i18n_1 = __importStar(require("i18n"));
41
+ const Repository_1 = __importDefault(require("../repositories/Repository"));
42
+ var pluralize = require('pluralize');
43
+ class ResourcesHelper {
44
+ static getSchemaTitle(schema, resource) {
45
+ if (resource.properties.title) {
46
+ return resource.properties.title;
47
+ }
48
+ return this.getTitle(schema);
49
+ }
50
+ static prepareProperties(properties, modelName, model, resource) {
51
+ var preparedProperties = [];
52
+ properties.forEach(key => {
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);
66
+ }
67
+ });
68
+ return preparedProperties;
69
+ }
70
+ static getFieldType(schemaField) {
71
+ if (schemaField.instance === 'Embedded') {
72
+ return helpers_1.FieldTypes.NESTEDSCHEMA;
73
+ }
74
+ if (schemaField.options.ref) {
75
+ return helpers_1.FieldTypes.REFERENCE;
76
+ }
77
+ else if (schemaField.enumValues && schemaField.enumValues.length !== 0) {
78
+ return helpers_1.FieldTypes.ENUM;
79
+ }
80
+ else {
81
+ return schemaField.instance;
82
+ }
83
+ }
84
+ static prepareFilterProperties(properties, schema) {
85
+ var filterProperties = [];
86
+ for (var i = 0; i < properties.length; i++) {
87
+ const property = properties[i];
88
+ if (!schema[property] || !schema[property].type || schema[property].type === helpers_1.FieldTypes.ARRAY || schema[property].type === helpers_1.FieldTypes.NESTEDSCHEMA || schema[property].type === helpers_1.FieldTypes.IMAGE || schema[property].type === helpers_1.FieldTypes.PASSWORD) {
89
+ continue;
90
+ }
91
+ filterProperties.push(property);
92
+ }
93
+ return filterProperties;
94
+ }
95
+ static checkResourceTranslation(resource, key) {
96
+ var translation = undefined;
97
+ if (!resource.properties.keysTranslations || !resource.properties.keysTranslations[key]) {
98
+ return translation;
99
+ }
100
+ if ((0, i18n_1.__)({ phrase: resource.properties.keysTranslations[key], locale: i18n_1.default.getLocale() }) !== resource.properties.keysTranslations[key]) {
101
+ translation = (0, i18n_1.__)({ phrase: resource.properties.keysTranslations[key], locale: i18n_1.default.getLocale() });
102
+ }
103
+ return translation;
104
+ }
105
+ static checkActionTranslation(resource, action) {
106
+ var translation = undefined;
107
+ if (!resource.properties.actionsTranslations || !resource.properties.actionsTranslations[action]) {
108
+ return translation;
109
+ }
110
+ translation = (0, i18n_1.__)({ phrase: resource.properties.actionsTranslations[action], locale: i18n_1.default.getLocale() });
111
+ return translation;
112
+ }
113
+ static setScopeFilterOptions(modelName, options) {
114
+ var arrayOfOptions = [];
115
+ arrayOfOptions.push({
116
+ key: 'all',
117
+ value: (0, i18n_1.__)({ phrase: 'ALL', locale: i18n_1.default.getLocale() })
118
+ });
119
+ options.forEach((key) => {
120
+ const optionObject = {
121
+ key,
122
+ value: (0, i18n_1.__)({ phrase: key, locale: i18n_1.default.getLocale() })
123
+ };
124
+ arrayOfOptions.push(optionObject);
125
+ });
126
+ return arrayOfOptions;
127
+ }
128
+ static getFilters(filters) {
129
+ var filterObject = {
130
+ scopes: {},
131
+ searchBar: {}
132
+ };
133
+ if (!filters || Object.keys(filters).length === 0) {
134
+ filterObject = {
135
+ scopes: {
136
+ isAccessible: false
137
+ },
138
+ searchBar: {
139
+ isAccessible: true
140
+ }
141
+ };
142
+ return filterObject;
143
+ }
144
+ if (!filters.searchBar || !filters.searchBar.hasOwnProperty('isAccessible')) {
145
+ filterObject.searchBar = {
146
+ isAccessible: true
147
+ };
148
+ }
149
+ else {
150
+ filterObject.searchBar = filters.searchBar;
151
+ }
152
+ if (!filters.scopes || !filters.scopes.hasOwnProperty('isAccessible')) {
153
+ filterObject.scopes = {
154
+ isAccessible: false
155
+ };
156
+ }
157
+ else {
158
+ filterObject.scopes = filters.scopes;
159
+ }
160
+ return filterObject;
161
+ }
162
+ static addExtraFields(showProperties, model, record, filterBy, resource) {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ for (var i = 0; i < showProperties.length; i++) {
165
+ const key = showProperties[i].key;
166
+ if ((model[key].type === helpers_1.FieldTypes.REFERENCE && model.virtuals && model.virtuals[key]) || (model[key].type === helpers_1.FieldTypes.ARRAY && model.virtuals && model.virtuals[key] && model[key].arrayType === helpers_1.FieldTypes.REFERENCE)) {
167
+ const resourceModel = resource.properties.model;
168
+ if (!resourceModel) {
169
+ return;
170
+ }
171
+ const virtuals = resourceModel.virtuals;
172
+ if (!virtuals) {
173
+ return;
174
+ }
175
+ const virtualModel = virtuals[key].resource;
176
+ if (!virtualModel) {
177
+ return;
178
+ }
179
+ const repository = new Repository_1.default(virtualModel);
180
+ filterBy = filterBy + "Id";
181
+ const filterQuery = {};
182
+ filterQuery[filterBy] = record._id;
183
+ const extraRecords = yield repository.findMany({
184
+ filter: filterQuery
185
+ });
186
+ record[showProperties[i].key] = extraRecords;
187
+ }
188
+ }
189
+ ;
190
+ return record;
191
+ });
192
+ }
193
+ static getTitle(schema) {
194
+ if (schema['title']) {
195
+ return 'title';
196
+ }
197
+ if (schema['name']) {
198
+ return 'name';
199
+ }
200
+ if (schema['email']) {
201
+ return 'email';
202
+ }
203
+ return '_id';
204
+ }
205
+ static exchangeFirstFieldWithTitle(arrayOfFields, title) {
206
+ if (arrayOfFields[0] !== title) {
207
+ for (var i = 1; i < arrayOfFields.length; i++) {
208
+ const field = arrayOfFields[i];
209
+ if (field === title) {
210
+ const temp = arrayOfFields[0];
211
+ arrayOfFields[0] = title;
212
+ arrayOfFields[i] = temp;
213
+ break;
214
+ }
215
+ }
216
+ }
217
+ return arrayOfFields;
218
+ }
219
+ static addVirtualFields(arrayOfFields, model) {
220
+ var showProperties = JSON.parse(JSON.stringify(arrayOfFields));
221
+ var listProperties = JSON.parse(JSON.stringify(arrayOfFields));
222
+ var formProperties = JSON.parse(JSON.stringify(arrayOfFields));
223
+ if (!model || !model.virtuals || !(Object.keys(model.virtuals))) {
224
+ return [listProperties, showProperties, formProperties];
225
+ }
226
+ const virtualFields = model.virtuals;
227
+ for (const extraField in virtualFields) {
228
+ if (virtualFields[extraField].showIn) {
229
+ switch (virtualFields[extraField].showIn) {
230
+ case helpers_1.Virtuals.SHOW:
231
+ showProperties.push(extraField);
232
+ break;
233
+ case helpers_1.Virtuals.LIST:
234
+ listProperties.push(extraField);
235
+ break;
236
+ case helpers_1.Virtuals.FORM:
237
+ formProperties.push(extraField);
238
+ break;
239
+ }
240
+ }
241
+ else {
242
+ showProperties.push(extraField);
243
+ listProperties.push(extraField);
244
+ formProperties.push(extraField);
245
+ }
246
+ }
247
+ return [listProperties, showProperties, formProperties];
248
+ }
249
+ static manageFields(schema, title, hiddenProperties) {
250
+ var arrayOfFields = [];
251
+ if (!hiddenProperties || !hiddenProperties.includes('_id')) {
252
+ arrayOfFields.push('_id');
253
+ }
254
+ if (title !== '_id' && (!hiddenProperties || !hiddenProperties.includes(title))) {
255
+ arrayOfFields.push(title);
256
+ }
257
+ const fields = Object.keys(schema);
258
+ for (var i = 0; i < fields.length; i++) {
259
+ const fieldKey = fields[i];
260
+ if (hiddenProperties && hiddenProperties.includes(fieldKey)) {
261
+ continue;
262
+ }
263
+ const unwantedField = this.checkUnwantedFields(fieldKey, title);
264
+ if (unwantedField) {
265
+ continue;
266
+ }
267
+ arrayOfFields.push(fieldKey);
268
+ }
269
+ return arrayOfFields;
270
+ }
271
+ static checkUnwantedFields(fieldKey, title) {
272
+ if (fieldKey === '__v' || fieldKey === '_id' || fieldKey === title || fieldKey === 'salt' || fieldKey === 'hash' || fieldKey === 'forgotPasswordToken' || fieldKey === 'encryptedPassword') {
273
+ return true;
274
+ }
275
+ return false;
276
+ }
277
+ static getModelPath(modelName) {
278
+ const modelPath = pluralize(StringUtils_1.default.lowerCaseFirstLetter(modelName));
279
+ return modelPath;
280
+ }
281
+ static removeUnWantedFieldsFromCreateOrUpdate(arrayOfFields) {
282
+ var modifiedArrayOfFields = [];
283
+ arrayOfFields.forEach(field => {
284
+ if (field !== '_id' && field !== 'createdAt' && field !== 'updatedAt') {
285
+ modifiedArrayOfFields.push(field);
286
+ }
287
+ });
288
+ return modifiedArrayOfFields;
289
+ }
290
+ // public static checkIndexBeforeHandler(resource: any) {
291
+ // const crudOperations = resource.properties.crudOperations
292
+ // if (crudOperations && crudOperations.index && crudOperations.index.before) {
293
+ // return true
294
+ // }
295
+ // return false
296
+ // }
297
+ static checkCreateBeforeHandler(resource) {
298
+ const crudOperations = resource.properties.crudOperations;
299
+ if (crudOperations && crudOperations.create && crudOperations.create.before) {
300
+ return true;
301
+ }
302
+ return false;
303
+ }
304
+ }
305
+ exports.default = ResourcesHelper;
@@ -1,5 +1,5 @@
1
- import { IResourceFile } from "../types/IResourceFile";
2
- export default class SchemaGenerator {
3
- static generateSchema(schema: any, model: any, modelName: string, resource: IResourceFile): any[];
4
- private static setNestedSchema;
5
- }
1
+ import { IResourceFile } from "../types/IResourceFile";
2
+ export default class SchemaGenerator {
3
+ static generateSchema(schema: any, model: any, modelName: string, resource: IResourceFile): any[];
4
+ private static setNestedSchema;
5
+ }