identity-admin 1.26.0 → 1.26.1

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,5 +1,5 @@
1
- import { IResourceFile } from "../types/IResourceFile";
2
- import { IModelConfigurationDocument } from "../models/modelConfiguration/IModelConfigurations";
1
+ import { IResourceFile } from '../types/IResourceFile';
2
+ import { IModelConfigurationDocument } from '../models/modelConfiguration/IModelConfigurations';
3
3
  export default class ResourcesHelper {
4
4
  static getSchemaTitle(schema: any, resource: any, modelConfiguration: IModelConfigurationDocument | undefined): any;
5
5
  static prepareProperties(properties: string[], modelName: string, model: any, resource: IResourceFile): {}[];
@@ -52,12 +52,12 @@ class ResourcesHelper {
52
52
  }
53
53
  static prepareProperties(properties, modelName, model, resource) {
54
54
  var preparedProperties = [];
55
- properties.forEach(key => {
55
+ properties.forEach((key) => {
56
56
  if (model[key]) {
57
57
  // const refCheck = model[key].type === FieldTypes.REFERENCE
58
58
  // var path = undefined
59
59
  // if (refCheck) {
60
- // path = model[key].path
60
+ // path = model[key].path
61
61
  // }
62
62
  // const translation = this.checkResourceTranslation(resource, key)
63
63
  // const propertyObject = {
@@ -85,15 +85,21 @@ class ResourcesHelper {
85
85
  const translatedKey = rawKey ? rawKey : key;
86
86
  const propertyObject = {
87
87
  key,
88
- 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),
89
- path: path
88
+ value: translation
89
+ ? translation
90
+ : model.value
91
+ ? model.value
92
+ : StringUtils_1.default.checkRefId(translatedKey)
93
+ ? StringUtils_1.default.convertCamelCaseToWord(translatedKey.slice(0, -2))
94
+ : StringUtils_1.default.convertCamelCaseToWord(translatedKey),
95
+ path: path,
90
96
  };
91
97
  return propertyObject;
92
98
  }
93
99
  static getRawName(key) {
94
100
  if (key.includes('.')) {
95
101
  const nestedProperties = key.split('.');
96
- return (nestedProperties[nestedProperties.length - 1]);
102
+ return nestedProperties[nestedProperties.length - 1];
97
103
  }
98
104
  return undefined;
99
105
  }
@@ -115,7 +121,12 @@ class ResourcesHelper {
115
121
  var filterProperties = [];
116
122
  for (var i = 0; i < properties.length; i++) {
117
123
  const property = properties[i];
118
- 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) {
124
+ if (!schema[property] ||
125
+ !schema[property].type ||
126
+ schema[property].type === helpers_1.FieldTypes.ARRAY ||
127
+ schema[property].type === helpers_1.FieldTypes.NESTEDSCHEMA ||
128
+ schema[property].type === helpers_1.FieldTypes.IMAGE ||
129
+ schema[property].type === helpers_1.FieldTypes.PASSWORD) {
119
130
  continue;
120
131
  }
121
132
  filterProperties.push(property);
@@ -144,12 +155,12 @@ class ResourcesHelper {
144
155
  var arrayOfOptions = [];
145
156
  arrayOfOptions.push({
146
157
  key: 'all',
147
- value: (0, i18n_1.__)({ phrase: 'ALL', locale: i18n_1.default.getLocale() })
158
+ value: (0, i18n_1.__)({ phrase: 'ALL', locale: i18n_1.default.getLocale() }),
148
159
  });
149
160
  options.forEach((key) => {
150
161
  const optionObject = {
151
162
  key,
152
- value: (0, i18n_1.__)({ phrase: key, locale: i18n_1.default.getLocale() })
163
+ value: (0, i18n_1.__)({ phrase: key, locale: i18n_1.default.getLocale() }),
153
164
  };
154
165
  arrayOfOptions.push(optionObject);
155
166
  });
@@ -158,22 +169,22 @@ class ResourcesHelper {
158
169
  static getFilters(filters) {
159
170
  var filterObject = {
160
171
  scopes: {},
161
- searchBar: {}
172
+ searchBar: {},
162
173
  };
163
174
  if (!filters || Object.keys(filters).length === 0) {
164
175
  filterObject = {
165
176
  scopes: {
166
- isAccessible: false
177
+ isAccessible: false,
167
178
  },
168
179
  searchBar: {
169
- isAccessible: true
170
- }
180
+ isAccessible: true,
181
+ },
171
182
  };
172
183
  return filterObject;
173
184
  }
174
185
  if (!filters.searchBar || !filters.searchBar.hasOwnProperty('isAccessible')) {
175
186
  filterObject.searchBar = {
176
- isAccessible: true
187
+ isAccessible: true,
177
188
  };
178
189
  }
179
190
  else {
@@ -181,7 +192,7 @@ class ResourcesHelper {
181
192
  }
182
193
  if (!filters.scopes || !filters.scopes.hasOwnProperty('isAccessible')) {
183
194
  filterObject.scopes = {
184
- isAccessible: false
195
+ isAccessible: false,
185
196
  };
186
197
  }
187
198
  else {
@@ -193,7 +204,8 @@ class ResourcesHelper {
193
204
  return __awaiter(this, void 0, void 0, function* () {
194
205
  for (var i = 0; i < showProperties.length; i++) {
195
206
  const key = showProperties[i].key;
196
- 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)) {
207
+ if ((model[key].type === helpers_1.FieldTypes.REFERENCE && model.virtuals && model.virtuals[key]) ||
208
+ (model[key].type === helpers_1.FieldTypes.ARRAY && model.virtuals && model.virtuals[key] && model[key].arrayType === helpers_1.FieldTypes.REFERENCE)) {
197
209
  const resourceModel = resource.properties.model;
198
210
  if (!resourceModel) {
199
211
  return;
@@ -207,16 +219,15 @@ class ResourcesHelper {
207
219
  return;
208
220
  }
209
221
  const repository = new Repository_1.default(virtualModel);
210
- filterBy = filterBy + "Id";
222
+ const oneToManyFilterKey = virtuals[key].filterBy ? virtuals[key].filterBy : filterBy + 'Id';
211
223
  const filterQuery = {};
212
- filterQuery[filterBy] = record._id;
224
+ filterQuery[oneToManyFilterKey] = record._id;
213
225
  const extraRecords = yield repository.findMany({
214
- filter: filterQuery
226
+ filter: filterQuery,
215
227
  });
216
228
  record[showProperties[i].key] = extraRecords;
217
229
  }
218
230
  }
219
- ;
220
231
  return record;
221
232
  });
222
233
  }
@@ -251,7 +262,7 @@ class ResourcesHelper {
251
262
  var listProperties = JSON.parse(JSON.stringify(arrayOfFields));
252
263
  var formProperties = JSON.parse(JSON.stringify(arrayOfFields));
253
264
  var filterProperties = JSON.parse(JSON.stringify(arrayOfFields));
254
- if (!model || !model.virtuals || !(Object.keys(model.virtuals))) {
265
+ if (!model || !model.virtuals || !Object.keys(model.virtuals)) {
255
266
  return [listProperties, showProperties, formProperties, filterProperties];
256
267
  }
257
268
  const virtualFields = model.virtuals;
@@ -304,7 +315,13 @@ class ResourcesHelper {
304
315
  return arrayOfFields;
305
316
  }
306
317
  static checkUnwantedFields(fieldKey, title) {
307
- if (fieldKey === '__v' || fieldKey === '_id' || fieldKey === title || fieldKey === 'salt' || fieldKey === 'hash' || fieldKey === 'forgotPasswordToken' || fieldKey === 'encryptedPassword') {
318
+ if (fieldKey === '__v' ||
319
+ fieldKey === '_id' ||
320
+ fieldKey === title ||
321
+ fieldKey === 'salt' ||
322
+ fieldKey === 'hash' ||
323
+ fieldKey === 'forgotPasswordToken' ||
324
+ fieldKey === 'encryptedPassword') {
308
325
  return true;
309
326
  }
310
327
  return false;
@@ -315,7 +332,7 @@ class ResourcesHelper {
315
332
  }
316
333
  static removeUnWantedFieldsFromCreateOrUpdate(arrayOfFields) {
317
334
  var modifiedArrayOfFields = [];
318
- arrayOfFields.forEach(field => {
335
+ arrayOfFields.forEach((field) => {
319
336
  if (field !== '_id' && field !== 'createdAt' && field !== 'updatedAt') {
320
337
  modifiedArrayOfFields.push(field);
321
338
  }
@@ -333,6 +333,10 @@ export interface IVirtualValue {
333
333
  * 3) array: If this field is an array
334
334
  */
335
335
  type: VirtualFieldTypes;
336
+ /**
337
+ * Specify the key that should be filtered by in case of 1 to many realtionship
338
+ */
339
+ filterBy?: string;
336
340
  /**
337
341
  * Array type exists only if the type is array
338
342
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.26.0",
3
+ "version": "1.26.1",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",