@reldens/cms 0.16.0 → 0.18.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.
@@ -0,0 +1,576 @@
1
+ /**
2
+ *
3
+ * Reldens - RouterContents
4
+ *
5
+ */
6
+
7
+ const { PageRangeProvider, Logger, sc } = require('@reldens/utils');
8
+ const { FileHandler } = require('@reldens/server-utils');
9
+
10
+ class RouterContents
11
+ {
12
+
13
+ constructor(props)
14
+ {
15
+ this.dataServer = props.dataServer;
16
+ this.translations = props.translations;
17
+ this.rootPath = props.rootPath;
18
+ this.relations = props.relations;
19
+ this.resourcesByReference = props.resourcesByReference;
20
+ this.adminFilesContents = props.adminFilesContents;
21
+ this.autoSyncDistCallback = props.autoSyncDistCallback;
22
+ this.viewPath = props.viewPath;
23
+ this.editPath = props.editPath;
24
+ this.deletePath = props.deletePath;
25
+ this.emitEvent = props.emitEvent;
26
+ this.adminContentsRender = props.adminContentsRender;
27
+ this.adminContentsRenderRoute = props.adminContentsRenderRoute;
28
+ this.adminContentsEntities = props.adminContentsEntities;
29
+ this.adminContentsSideBar = props.adminContentsSideBar;
30
+ this.fetchTranslation = props.fetchTranslation;
31
+ this.fetchEntityIdPropertyKey = props.fetchEntityIdPropertyKey;
32
+ this.fetchUploadProperties = props.fetchUploadProperties;
33
+ }
34
+
35
+ async generateListRouteContent(req, driverResource, entityPath)
36
+ {
37
+ let currentPage = Number(req?.query?.page || 1);
38
+ let pageSize = Number(req?.query?.pageSize || 25);
39
+ let filtersFromParams = req?.body?.filters || {};
40
+ let filters = this.prepareFilters(filtersFromParams, driverResource);
41
+ let totalEntities = await this.countTotalEntities(driverResource, filters);
42
+ let totalPages = totalEntities <= pageSize ? 1 : Math.ceil(totalEntities / pageSize);
43
+ let renderedPagination = '';
44
+ for(let paginationItem of PageRangeProvider.fetch(currentPage, totalPages)){
45
+ renderedPagination += await this.adminContentsRender(
46
+ this.adminFilesContents.fields.view['link'],
47
+ {
48
+ fieldName: paginationItem.label,
49
+ fieldValue: this.rootPath+'/'+driverResource.entityPath+'?page='+ paginationItem.value,
50
+ fieldOriginalValue: paginationItem.value,
51
+ }
52
+ );
53
+ }
54
+ return await this.adminContentsRenderRoute(
55
+ await this.adminContentsRender(
56
+ this.adminContentsEntities()[entityPath].list,
57
+ Object.assign({
58
+ list: await this.adminContentsRender(this.adminFilesContents.listContent, {
59
+ deletePath: this.rootPath + '/' + driverResource.entityPath + this.deletePath,
60
+ fieldsHeaders: driverResource.options.listProperties.map((property) => {
61
+ let propertyTitle = this.fetchTranslation(property, driverResource.id());
62
+ let alias = this.fetchTranslation(
63
+ driverResource.options.properties[property]?.alias || '',
64
+ driverResource.id()
65
+ );
66
+ return {name: property, value: '' !== alias ? alias + ' ('+propertyTitle+')' : propertyTitle};
67
+ }),
68
+ rows: await this.loadEntitiesForList(driverResource, pageSize, currentPage, req, filters)
69
+ }),
70
+ pagination: renderedPagination
71
+ }, ...driverResource.options.filterProperties.map((property) => {
72
+ let filterValue = (filtersFromParams[property] || '');
73
+ return {[property]: '' === filterValue ? '' : 'value="'+filterValue+'"'};
74
+ }))
75
+ ),
76
+ this.adminContentsSideBar()
77
+ );
78
+ }
79
+
80
+ async generateViewRouteContent(req, driverResource, entityPath)
81
+ {
82
+ let idProperty = this.fetchEntityIdPropertyKey(driverResource);
83
+ let id = (sc.get(req.query, idProperty, ''));
84
+ if('' === id){
85
+ Logger.error('Missing ID on view route.', entityPath, id, idProperty);
86
+ return '';
87
+ }
88
+ let loadedEntity = await this.loadEntityById(driverResource, id);
89
+ let renderedViewProperties = {
90
+ entityEditRoute: this.generateEntityRoute('editPath', driverResource, idProperty, loadedEntity),
91
+ entityNewRoute: this.rootPath+'/'+driverResource.entityPath+this.editPath,
92
+ id
93
+ };
94
+ let entitySerializedData = {};
95
+ for(let propertyKey of driverResource.options.showProperties){
96
+ let property = driverResource.options.properties[propertyKey];
97
+ let {fieldValue, fieldName} = this.generatePropertyRenderedValueWithLabel(
98
+ loadedEntity,
99
+ propertyKey,
100
+ property
101
+ );
102
+ entitySerializedData[fieldName] = fieldValue;
103
+ renderedViewProperties[propertyKey] = await this.generatePropertyRenderedValue(
104
+ fieldValue,
105
+ fieldName,
106
+ property,
107
+ 'view'
108
+ );
109
+ }
110
+ let extraDataEvent = {entitySerializedData, entityId: driverResource.id(), entity: loadedEntity};
111
+ await this.emitEvent('adminEntityExtraData', extraDataEvent);
112
+ renderedViewProperties.entitySerializedData = JSON.stringify(extraDataEvent.entitySerializedData).replace(/"/g, '&quot;');
113
+ await this.emitEvent('reldens.adminViewPropertiesPopulation', {
114
+ idProperty,
115
+ req,
116
+ driverResource,
117
+ loadedEntity,
118
+ renderedViewProperties
119
+ });
120
+ return await this.adminContentsRenderRoute(
121
+ await this.adminContentsRender(this.adminContentsEntities()[entityPath].view, renderedViewProperties),
122
+ this.adminContentsSideBar()
123
+ );
124
+ }
125
+
126
+ async generateEditRouteContent(req, driverResource, entityPath)
127
+ {
128
+ let idProperty = this.fetchEntityIdPropertyKey(driverResource);
129
+ let idValue = String(sc.get(req?.query, idProperty, ''));
130
+ let loadedEntity = !idValue ? null : await this.loadEntityById(driverResource, idValue);
131
+ let renderedEditProperties = {
132
+ idValue,
133
+ idProperty,
134
+ idPropertyLabel: this.fetchTranslation(idProperty),
135
+ templateTitle: (!idValue ? 'Create' : 'Edit')+' '+this.translations.labels[driverResource.id()],
136
+ entityViewRoute: !idValue
137
+ ? this.rootPath+'/'+driverResource.entityPath
138
+ : this.generateEntityRoute('viewPath', driverResource, idProperty, loadedEntity)
139
+ };
140
+ await this.emitEvent('reldens.adminEditPropertiesPopulation', {
141
+ req,
142
+ driverResource,
143
+ renderedEditProperties,
144
+ loadedEntity
145
+ });
146
+ for(let propertyKey of Object.keys(driverResource.options.properties)){
147
+ let property = driverResource.options.properties[propertyKey];
148
+ let fieldDisabled = -1 === driverResource.options.editProperties.indexOf(propertyKey);
149
+ renderedEditProperties[propertyKey] = await this.adminContentsRender(
150
+ this.adminFilesContents.fields.edit[this.propertyType(property, 'edit')],
151
+ {
152
+ fieldName: propertyKey,
153
+ fieldValue: await this.generatePropertyEditRenderedValue(
154
+ loadedEntity,
155
+ propertyKey,
156
+ property,
157
+ fieldDisabled
158
+ ),
159
+ fieldDisabled: fieldDisabled ? ' disabled="disabled"' : '',
160
+ required: (!property.isUpload || !loadedEntity) && property.isRequired ? ' required="required"' : '',
161
+ multiple: property.isArray ? ' multiple="multiple"' : '',
162
+ inputType: this.getInputType(property, fieldDisabled)
163
+ }
164
+ );
165
+ }
166
+ return await this.adminContentsRenderRoute(
167
+ await this.adminContentsRender(this.adminContentsEntities()[entityPath].edit, renderedEditProperties),
168
+ this.adminContentsSideBar()
169
+ );
170
+ }
171
+
172
+ async processDeleteEntities(req, res, driverResource, entityPath)
173
+ {
174
+ let ids = req?.body?.ids;
175
+ if('string' === typeof ids){
176
+ ids = ids.split(',');
177
+ }
178
+ let redirectPath = this.rootPath+'/'+entityPath+'?result=';
179
+ if(!ids || 0 === ids.length){
180
+ return redirectPath + 'errorMissingId';
181
+ }
182
+ try {
183
+ let entityRepository = this.dataServer.getEntity(driverResource.entityKey);
184
+ let idProperty = this.fetchEntityIdPropertyKey(driverResource);
185
+ let idsFilter = {[idProperty]: {operator: 'IN', value: ids}};
186
+ let loadedEntities = await entityRepository.load(idsFilter);
187
+ await this.deleteEntitiesRelatedFiles(driverResource, loadedEntities);
188
+ let deleteResult = await entityRepository.delete(idsFilter);
189
+ return redirectPath + (deleteResult ? 'success' : 'errorStorageFailure');
190
+ } catch (error) {
191
+ return redirectPath + 'errorDeleteFailure';
192
+ }
193
+ }
194
+
195
+ async processSaveEntity(req, res, driverResource, entityPath)
196
+ {
197
+ let idProperty = this.fetchEntityIdPropertyKey(driverResource);
198
+ let id = (req?.body[idProperty] || '');
199
+ let entityRepository = this.dataServer.getEntity(driverResource.entityKey);
200
+ let entityDataPatch = this.preparePatchData(driverResource, idProperty, req, driverResource.options.properties, id);
201
+ if(!entityDataPatch){
202
+ Logger.error('Bad patch data.', entityDataPatch);
203
+ return this.rootPath+'/'+entityPath+'?result=saveBadPatchData';
204
+ }
205
+ try {
206
+ let saveResult = await this.saveEntity(id, entityRepository, entityDataPatch);
207
+ if(!saveResult){
208
+ Logger.error('Save result error.', saveResult, entityDataPatch);
209
+ return this.generateEntityRoute('editPath', driverResource, idProperty, null, id)+'?result=saveEntityStorageError';
210
+ }
211
+ await this.emitEvent('reldens.adminAfterEntitySave', {
212
+ req,
213
+ res,
214
+ driverResource,
215
+ entityPath,
216
+ entityData: saveResult
217
+ });
218
+ if(sc.isFunction(this.autoSyncDistCallback)){
219
+ let uploadProperties = this.fetchUploadProperties(driverResource);
220
+ if(0 < Object.keys(uploadProperties).length){
221
+ for(let uploadPropertyKey of Object.keys(uploadProperties)){
222
+ let property = uploadProperties[uploadPropertyKey];
223
+ await this.autoSyncDistCallback(
224
+ property.bucket,
225
+ saveResult[uploadPropertyKey],
226
+ property.distFolder
227
+ );
228
+ }
229
+ }
230
+ }
231
+ if('saveAndContinue' === sc.get(req.body, 'saveAction', 'save')){
232
+ return this.generateEntityRoute('editPath', driverResource, idProperty, saveResult) +'&result=success';
233
+ }
234
+ return this.generateEntityRoute('viewPath', driverResource, idProperty, saveResult) +'&result=success';
235
+ } catch (error) {
236
+ Logger.error('Save entity error.', error);
237
+ return this.rootPath+'/'+entityPath+'?result=saveEntityError';
238
+ }
239
+ }
240
+
241
+ async countTotalEntities(driverResource, filters)
242
+ {
243
+ let entityRepository = this.dataServer.getEntity(driverResource.entityKey);
244
+ if(!entityRepository){
245
+ return false;
246
+ }
247
+ return await entityRepository.count(filters);
248
+ }
249
+
250
+ async loadEntitiesForList(driverResource, pageSize, currentPage, req, filters)
251
+ {
252
+ let entityRepository = this.dataServer.getEntity(driverResource.entityKey);
253
+ entityRepository.limit = pageSize;
254
+ if(1 < currentPage){
255
+ entityRepository.offset = (currentPage - 1) * pageSize;
256
+ }
257
+ entityRepository.sortBy = req?.body?.sortBy || false;
258
+ entityRepository.sortDirection = req?.body?.sortDirection || false;
259
+ let loadedEntities = await entityRepository.loadWithRelations(filters, []);
260
+ entityRepository.limit = 0;
261
+ entityRepository.offset = 0;
262
+ entityRepository.sortBy = false;
263
+ entityRepository.sortDirection = false;
264
+ let entityRows = [];
265
+ let resourceProperties = driverResource.options?.properties;
266
+ let idProperty = this.fetchEntityIdPropertyKey(driverResource);
267
+ for(let entity of loadedEntities){
268
+ let fields = [];
269
+ for(let property of driverResource.options.listProperties){
270
+ let {fieldValue, fieldName} = this.generatePropertyRenderedValueWithLabel(
271
+ entity,
272
+ property,
273
+ resourceProperties[property]
274
+ );
275
+ fields.push({
276
+ name: property,
277
+ value: await this.generatePropertyRenderedValue(fieldValue, fieldName, resourceProperties[property]),
278
+ viewLink: '' !== idProperty ? this.generateEntityRoute('viewPath', driverResource, idProperty, entity) : ''
279
+ });
280
+ }
281
+ entityRows.push({
282
+ fields,
283
+ editLink: '' !== idProperty ? this.generateEntityRoute('editPath', driverResource, idProperty, entity) : '',
284
+ deleteLink: this.rootPath + '/' + driverResource.entityPath + this.deletePath,
285
+ id: entity[idProperty]
286
+ });
287
+ }
288
+ return entityRows;
289
+ }
290
+
291
+ async loadEntityById(driverResource, id)
292
+ {
293
+ let entityRepository = this.dataServer.getEntity(driverResource.entityKey);
294
+ if(!entityRepository){
295
+ return false;
296
+ }
297
+ await this.emitEvent('reldens.adminBeforeEntityLoad', {
298
+ driverResource,
299
+ entityId: id
300
+ });
301
+ return await entityRepository.loadByIdWithRelations(id);
302
+ }
303
+
304
+ async saveEntity(id, entityRepository, entityDataPatch)
305
+ {
306
+ if('' === id){
307
+ return entityRepository.create(entityDataPatch);
308
+ }
309
+ return entityRepository.updateById(id, entityDataPatch);
310
+ }
311
+
312
+ async deleteEntitiesRelatedFiles(driverResource, entities)
313
+ {
314
+ for(let propertyKey of Object.keys(driverResource.options.properties)){
315
+ let property = driverResource.options.properties[propertyKey];
316
+ if(!property.isUpload){
317
+ continue;
318
+ }
319
+ for(let entity of entities){
320
+ if(!property.isArray){
321
+ FileHandler.remove([(property.bucket || ''), entity[propertyKey]]);
322
+ continue;
323
+ }
324
+ for(let entityFile of entity[propertyKey].split(property.isArray)){
325
+ FileHandler.remove([(property.bucket || ''), entityFile]);
326
+ }
327
+ }
328
+ }
329
+ }
330
+
331
+ preparePatchData(driverResource, idProperty, req, resourceProperties, id)
332
+ {
333
+ let entityDataPatch = {};
334
+ for(let i of driverResource.options.editProperties){
335
+ if(i === idProperty){
336
+ continue;
337
+ }
338
+ let propertyUpdateValue = sc.get(req.body, i, null);
339
+ let property = resourceProperties[i];
340
+ let propertyType = property.type || 'string';
341
+ if(property.isUpload){
342
+ propertyType = 'upload';
343
+ propertyUpdateValue = this.prepareUploadPatchData(req, i, propertyUpdateValue, property);
344
+ }
345
+ if('boolean' === propertyType){
346
+ propertyUpdateValue = '1' === propertyUpdateValue || 'on' === propertyUpdateValue;
347
+ }
348
+ if('number' === propertyType && null !== propertyUpdateValue && '' !== propertyUpdateValue){
349
+ propertyUpdateValue = Number(propertyUpdateValue);
350
+ }
351
+ if('string' === propertyType && null !== propertyUpdateValue && '' !== propertyUpdateValue){
352
+ propertyUpdateValue = String(propertyUpdateValue);
353
+ }
354
+ if('' === propertyUpdateValue && !property.isRequired){
355
+ propertyUpdateValue = null;
356
+ }
357
+ let isUploadCreate = property.isUpload && !id;
358
+ if(property.isRequired && (null === propertyUpdateValue || '' === propertyUpdateValue) && (!property.isUpload || isUploadCreate)){
359
+ Logger.critical('Bad patch data on update.', propertyUpdateValue, property);
360
+ return false;
361
+ }
362
+ if(!property.isUpload || (property.isUpload && null !== propertyUpdateValue)){
363
+ entityDataPatch[i] = propertyUpdateValue;
364
+ }
365
+ }
366
+ return entityDataPatch;
367
+ }
368
+
369
+ prepareUploadPatchData(req, i, propertyUpdateValue, property)
370
+ {
371
+ let filesData = sc.get(req.files, i, null);
372
+ if(null === filesData){
373
+ return null;
374
+ }
375
+ let fileNames = [];
376
+ for(let file of filesData){
377
+ fileNames.push(file.filename);
378
+ }
379
+ return fileNames.join(property.isArray);
380
+ }
381
+
382
+ async generatePropertyRenderedValue(fieldValue, fieldName, resourceProperty, templateType)
383
+ {
384
+ let fieldOriginalValue = fieldValue;
385
+ if('view' === templateType){
386
+ if(resourceProperty.isArray){
387
+ fieldValue = fieldValue.split(resourceProperty.isArray).map((value) => {
388
+ let target = resourceProperty.isUpload ? ' target="_blank"' : '';
389
+ let fieldValuePart = resourceProperty.isUpload && resourceProperty.bucketPath
390
+ ? resourceProperty.bucketPath+value
391
+ : value;
392
+ return {fieldValuePart, fieldOriginalValuePart: value, target};
393
+ });
394
+ }
395
+ if(!resourceProperty.isArray && resourceProperty.isUpload){
396
+ fieldValue = resourceProperty.bucketPath+fieldValue;
397
+ }
398
+ }
399
+ return await this.adminContentsRender(
400
+ this.adminFilesContents.fields.view[this.propertyType(resourceProperty, templateType)],
401
+ {fieldName, fieldValue, fieldOriginalValue, target: ' target="_blank"'}
402
+ );
403
+ }
404
+
405
+ generatePropertyRenderedValueWithLabel(entity, propertyKey, resourceProperty)
406
+ {
407
+ let fieldValue = (0 === entity[propertyKey] ? '0' : entity[propertyKey] || '');
408
+ let fieldName = propertyKey;
409
+ if('boolean' === resourceProperty.type){
410
+ fieldValue = 1 === entity[propertyKey] || '1' === entity[propertyKey] || true === entity[propertyKey] ? 'Yes' : 'No';
411
+ }
412
+ if('datetime' === resourceProperty.type){
413
+ fieldValue = '' !== fieldValue ? sc.formatDate(new Date(fieldValue)) : '';
414
+ }
415
+ if('reference' === resourceProperty.type){
416
+ let relationEntity = entity[resourceProperty.alias || resourceProperty.reference];
417
+ if(relationEntity){
418
+ let relation = this.relations()[resourceProperty.reference];
419
+ if(relation){
420
+ let relationTitleProperty = relation[resourceProperty.alias || resourceProperty.reference];
421
+ if(relationTitleProperty && '' !== String(relationEntity[relationTitleProperty] || '')){
422
+ fieldName = relationTitleProperty;
423
+ fieldValue = relationEntity[relationTitleProperty]+(' ('+fieldValue+')');
424
+ }
425
+ }
426
+ }
427
+ }
428
+ if(resourceProperty.availableValues){
429
+ let optionData = resourceProperty.availableValues.filter((availableValue) => {
430
+ return String(availableValue.value) === String(fieldValue);
431
+ }).shift();
432
+ if(optionData){
433
+ fieldValue = optionData.label + ' (' + fieldValue + ')';
434
+ }
435
+ }
436
+ return {fieldValue, fieldName};
437
+ }
438
+
439
+ async generatePropertyEditRenderedValue(entity, propertyKey, resourceProperty)
440
+ {
441
+ let entityPropertyValue = sc.get(entity, propertyKey, null);
442
+ let fieldValue = (0 === entityPropertyValue ? '0' : entityPropertyValue || '');
443
+ if('boolean' === resourceProperty.type){
444
+ fieldValue = 1 === entityPropertyValue || '1' === entityPropertyValue || true === entityPropertyValue ? ' checked="checked"' : '';
445
+ }
446
+ if('datetime' === resourceProperty.type){
447
+ fieldValue = !entityPropertyValue || '' === entityPropertyValue
448
+ ? ''
449
+ : sc.formatDate(new Date(entityPropertyValue), 'Y-m-d H:i:s');
450
+ }
451
+ if('reference' === resourceProperty.type){
452
+ let relationDriverResource = this.resourcesByReference()[resourceProperty.reference];
453
+ let relation = this.relations()[resourceProperty.reference];
454
+ let relationKey = resourceProperty.alias || resourceProperty.reference;
455
+ let relationTitleProperty = relation ? relation[relationKey] : this.fetchEntityIdPropertyKey(relationDriverResource);
456
+ let options = (await this.fetchRelationOptions(relationDriverResource)).map((option) => {
457
+ let value = option[this.fetchEntityIdPropertyKey(relationDriverResource)];
458
+ return {
459
+ label: option[relationTitleProperty]+' (ID: '+value+')',
460
+ value,
461
+ selected: entity && entity[propertyKey] === value ? ' selected="selected"' : ''
462
+ };
463
+ });
464
+ if(!resourceProperty.isRequired){
465
+ options.unshift({
466
+ label: '-- Select --',
467
+ value: '',
468
+ selected: (!entity || null === entity[propertyKey] || '' === entity[propertyKey]) ? ' selected="selected"' : ''
469
+ });
470
+ }
471
+ return options;
472
+ }
473
+ return fieldValue;
474
+ }
475
+
476
+ async fetchRelationOptions(relationDriverResource)
477
+ {
478
+ let relationEntityRepository = this.dataServer.getEntity(relationDriverResource.entityKey);
479
+ return await relationEntityRepository.loadAll();
480
+ }
481
+
482
+ propertyType(resourceProperty, templateType)
483
+ {
484
+ let propertyType = sc.get(resourceProperty, 'type', 'text');
485
+ if('reference' === propertyType && 'edit' === templateType){
486
+ return 'select';
487
+ }
488
+ if(resourceProperty.isUpload){
489
+ if('edit' === templateType){
490
+ return 'file';
491
+ }
492
+ if('view' === templateType){
493
+ let multiple = resourceProperty.isArray ? 's' : '';
494
+ if('image' === resourceProperty.allowedTypes){
495
+ return resourceProperty.allowedTypes + multiple;
496
+ }
497
+ if('text' === resourceProperty.allowedTypes){
498
+ return 'link'+multiple
499
+ }
500
+ return 'text';
501
+ }
502
+ }
503
+ if('textarea' === resourceProperty.type){
504
+ return 'textarea';
505
+ }
506
+ if(-1 !== ['reference', 'number', 'datetime'].indexOf(propertyType)){
507
+ propertyType = 'text';
508
+ }
509
+ return propertyType;
510
+ }
511
+
512
+ getInputType(resourceProperty, fieldDisabled)
513
+ {
514
+ if('datetime' === resourceProperty.type && !fieldDisabled){
515
+ return 'datetime-local';
516
+ }
517
+ if('number' === resourceProperty.type){
518
+ return 'number';
519
+ }
520
+ return 'text';
521
+ }
522
+
523
+ generateEntityRoute(routeType, driverResource, idProperty, entity, entityId)
524
+ {
525
+ if(!idProperty || (!entity && !entityId)){
526
+ return this.rootPath + '/' + driverResource.entityPath;
527
+ }
528
+ let idParam = '?' + idProperty + '=';
529
+ if(entity){
530
+ idParam = idParam + entity[idProperty];
531
+ }
532
+ if(entityId){
533
+ idParam = idParam + entityId;
534
+ }
535
+ return this.rootPath + '/' + driverResource.entityPath + this[routeType] + idParam;
536
+ }
537
+
538
+ prepareFilters(filtersList, driverResource)
539
+ {
540
+ if(0 === Object.keys(filtersList).length){
541
+ return {};
542
+ }
543
+ let filters = {};
544
+ for(let i of Object.keys(filtersList)){
545
+ let filter = filtersList[i];
546
+ if('' === filter || null === filter || undefined === filter){
547
+ continue;
548
+ }
549
+ let rawConfigFilterProperties = driverResource.options.properties[i];
550
+ if(!rawConfigFilterProperties){
551
+ Logger.critical('Could not found property by key.', i);
552
+ continue;
553
+ }
554
+ if(rawConfigFilterProperties.isUpload){
555
+ continue;
556
+ }
557
+ if('reference' === rawConfigFilterProperties.type){
558
+ filters[i] = Number(filter);
559
+ continue;
560
+ }
561
+ if('boolean' === rawConfigFilterProperties.type){
562
+ filters[i] = ('true' === filter || '1' === filter || 1 === filter);
563
+ continue;
564
+ }
565
+ if('number' === rawConfigFilterProperties.type || rawConfigFilterProperties.isId){
566
+ filters[i] = Number(filter);
567
+ continue;
568
+ }
569
+ filters[i] = {operator: 'LIKE', value: '%'+filter+'%'};
570
+ }
571
+ return filters;
572
+ }
573
+
574
+ }
575
+
576
+ module.exports.RouterContents = RouterContents;