@onehat/data 1.22.17 → 1.22.19
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.
- package/cypress/e2e/Repository/Ajax.cy.js +15 -0
- package/package.json +1 -1
- package/src/Entity/Entity.js +10 -11
- package/src/Repository/Ajax.js +13 -0
|
@@ -38,6 +38,21 @@ describe('OneBuildRepository', function() {
|
|
|
38
38
|
expect(r._params.test).to.be.eq(1);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
+
it('getBaseParamConditions', function() {
|
|
42
|
+
const
|
|
43
|
+
r = this.repository,
|
|
44
|
+
newConditions = {
|
|
45
|
+
'conditions[Model.model]': 'test1',
|
|
46
|
+
'conditions[Model.modelid]': 'test2',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
r.setBaseParams(newConditions);
|
|
50
|
+
|
|
51
|
+
const conditions = r.getBaseParamConditions();
|
|
52
|
+
|
|
53
|
+
expect(conditions).to.eql(newConditions);
|
|
54
|
+
});
|
|
55
|
+
|
|
41
56
|
it('hasParam', function() {
|
|
42
57
|
const r = this.repository;
|
|
43
58
|
r.setParam('test', 1);
|
package/package.json
CHANGED
package/src/Entity/Entity.js
CHANGED
|
@@ -115,16 +115,6 @@ class Entity extends EventEmitter {
|
|
|
115
115
|
*/
|
|
116
116
|
this.isTree = schema.repository.type === 'tree' || false;
|
|
117
117
|
|
|
118
|
-
if (this.isTree && !schema.model.parentIdProperty) {
|
|
119
|
-
throw new Error('parentIdProperty cannot be empty for a TreeNode');
|
|
120
|
-
}
|
|
121
|
-
if (this.isTree && this.repository?.isClosureTable && !schema.model.depthProperty) {
|
|
122
|
-
throw new Error('depthProperty cannot be empty for a Closure Table TreeNode');
|
|
123
|
-
}
|
|
124
|
-
if (this.isTree && !schema.model.hasChildrenProperty) {
|
|
125
|
-
throw new Error('hasChildrenProperty cannot be empty for a TreeNode');
|
|
126
|
-
}
|
|
127
|
-
|
|
128
118
|
/**
|
|
129
119
|
* @member {TreeNode} parent - The parent TreeNode for this TreeNode
|
|
130
120
|
* @public
|
|
@@ -346,7 +336,16 @@ class Entity extends EventEmitter {
|
|
|
346
336
|
if (this.isDestroyed) {
|
|
347
337
|
throw Error('this._createProperties is no longer valid. Entity has been destroyed.');
|
|
348
338
|
}
|
|
349
|
-
|
|
339
|
+
let propertyDefinitions = this.schema.model.properties;
|
|
340
|
+
if (this.isTree) {
|
|
341
|
+
const treePropertyDefinitions = [
|
|
342
|
+
// defaults
|
|
343
|
+
{ name: 'parentId', mapping: 'parentId', type: 'int', isEditingDisabled: true, isFilteringDisabled: true, },
|
|
344
|
+
{ name: 'hasChildren', mapping: 'hasChildren', type: 'bool', isEditingDisabled: true, isFilteringDisabled: true, },
|
|
345
|
+
{ name: 'depth', mapping: 'depth', type: 'int', isEditingDisabled: true, isFilteringDisabled: true, },
|
|
346
|
+
];
|
|
347
|
+
propertyDefinitions = _.unionBy(propertyDefinitions, treePropertyDefinitions, 'name'); // propertyDefinitions will override treePropertyDefinitions
|
|
348
|
+
}
|
|
350
349
|
let properties = {};
|
|
351
350
|
_.each(propertyDefinitions, (definition) => {
|
|
352
351
|
if (!definition.name) {
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -354,6 +354,19 @@ class AjaxRepository extends Repository {
|
|
|
354
354
|
return this._baseParams;
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Returns current value of any baseParam query conditions
|
|
359
|
+
*/
|
|
360
|
+
getBaseParamConditions() {
|
|
361
|
+
const
|
|
362
|
+
existingConditions = this._baseParams.conditions || {},
|
|
363
|
+
convertedConditions = {};
|
|
364
|
+
_.each(existingConditions, (value, key) => {
|
|
365
|
+
convertedConditions['conditions[' + key + ']'] = value;
|
|
366
|
+
});
|
|
367
|
+
return convertedConditions;
|
|
368
|
+
}
|
|
369
|
+
|
|
357
370
|
/**
|
|
358
371
|
* Determines if query param exists
|
|
359
372
|
* @param {string} name - Param name
|