Skip to content

Commit

Permalink
Allow multiple operators in Where class for each property (#95)
Browse files Browse the repository at this point in the history
# Description

This PR addresses an issue where the Where class in Neogma was not
allowing multiple operators per property. This change fixes that
omission, enabling the use of multiple operators for each property in
the Where class.

## Type of change
- [X] Bug fix (non-breaking change which fixes an issue)

# How Has This Been Tested?

To verify these changes, I performed the following tests:

- [X] Test for adding two operators to a property

**Test Configuration**:

- SDK: Jest
- Software version: 26
- Toolchain: super-test

# Checklist:

- [X] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [X] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
fernandovargascabrera authored Mar 14, 2024
1 parent 7bb78ab commit 100d8f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/Queries/Where/Where.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,38 @@ describe('Where', () => {

expect(where.getBindParam().get()).toEqual(expectedValues);
});

it('Support more than one operator per property', () => {
const where = new Where({
identifier: {
property: {
[Op.gte]: '2021-01-01',
[Op.lte]: '2023-01-01',
},
primaryProperty: {
[Op.eq]: 'someId',
},
},
});
const whereString = where.getStatement('text');
expect(
whereString.includes(
'identifier.property >= $property AND identifier.property <= $property__aaaa',
),
).toBeTruthy();

expect(
whereString.includes('identifier.primaryProperty = $primaryProperty'),
).toBeTruthy();

try {
where.getStatement('object');
} catch (error) {
expect(error.message).toEqual(
'The only operator which is supported for object mode is "eq"',
);
}
});
});

describe('addParams', () => {
Expand Down
9 changes: 5 additions & 4 deletions src/Queries/Where/Where.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,17 @@ export class Where {
value,
operator: 'eq',
});
} else if (value !== null && value !== undefined) {
for (const operator of operators) {
if (isOperator[operator](value)) {
} else if (value !== null && typeof value === 'object') {
const symbols = Object.getOwnPropertySymbols(value);
for (const { description } of symbols) {
const operator = description as (typeof operators)[number];
if (operator && isOperator[operator]?.(value)) {
this.addBindParamDataEntry({
identifier: nodeIdentifier,
property,
value: value[Op[operator]],
operator,
});
break;
}
}
}
Expand Down

0 comments on commit 100d8f3

Please sign in to comment.