Skip to content

Commit

Permalink
Merge pull request #11 from sisimomo/10-fix-operator-not
Browse files Browse the repository at this point in the history
fix(not-operator): improved not operator handling in toString() method fixing issue #10
  • Loading branch information
sisimomo authored Aug 24, 2023
2 parents fad8e25 + 4fa3a2e commit 6688153
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spring-filter-query-builder",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
5 changes: 4 additions & 1 deletion src/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export class Not extends Operator {
}

public toString(): string {
return `${this.operatorKeyWord} ${this.items[0].toString()}`;
if (this.items[0] instanceof Operator) {
return `${this.operatorKeyWord}${this.items[0].toString()}`;
}
return `${this.operatorKeyWord}(${this.items[0].toString()})`;
}
}

Expand Down
6 changes: 5 additions & 1 deletion test/operators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ test('or', () => {
});

test('not', () => {
expect(sfNot(sfOr([sfGt('id', 100), sfIsNull('category.order')])).toString()).toBe('not (id > 100 or category.order is null)');
expect(sfNot(sfOr([sfGt('id', 100), sfIsNull('category.order')])).toString()).toBe('not(id > 100 or category.order is null)');
});

test('not', () => {
expect(sfNot(sfGt('id', 100)).toString()).toBe('not(id > 100)');
});

0 comments on commit 6688153

Please sign in to comment.