From d9b585e48a7346a9f6e405718ee1fc1d886bf526 Mon Sep 17 00:00:00 2001 From: Trent Hibbard Date: Thu, 29 Jul 2021 13:48:03 -0400 Subject: [PATCH 1/2] Allow grouped OR in queries --- src/services/Where.ts | 4 ++++ test/Where.spec.ts | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/services/Where.ts b/src/services/Where.ts index 30d607c..e21c2d6 100644 --- a/src/services/Where.ts +++ b/src/services/Where.ts @@ -120,6 +120,10 @@ export class Where { const value = data[key]; if (key === 'or') { queries.push(`(${Where.toQuerySyntax(value).replace(/ AND /g, ' OR ')})`); + } else if (key === 'groupedOr' && Array.isArray(value) && value.length > 0) { + queries.push(`(${value.map((group) => { + return `(${Where.toQuerySyntax(group)})`; + }).join(' OR ')})`); } else if (key === 'orMinMax') { for (const subkey of Object.keys(value)) { queries.push(`(${Where.parseQueryValue(subkey, value[subkey])})`); diff --git a/test/Where.spec.ts b/test/Where.spec.ts index d2ab6a6..ac4beb5 100644 --- a/test/Where.spec.ts +++ b/test/Where.spec.ts @@ -110,6 +110,43 @@ describe('Where', () => { }); }); + describe('with groupedOr queries', () => { + it('should create a valid grouped OR query', () => { + const where = Where.toQuerySyntax({ + title: 'Mr. President', + groupedOr: [{ + firstName: 'Abe', + lastName: 'Lincoln', + }, { + owner: { + firstName: 'Abe', + lastName: 'Lincoln', + }, + }] + }); + + expect(where).toEqual("title='Mr. President' AND ((firstName='Abe' AND lastName='Lincoln') OR (owner.firstName='Abe' AND owner.lastName='Lincoln'))"); + }); + it('should create a valid OR query with 3 or more grouped or conditions', () => { + const where = Where.toQuerySyntax({ + groupedOr: [{ + firstName: 'Abe', + lastName: 'Lincoln', + title: 'Mr. President', + }, { + owner: { + firstName: 'Abe', + lastName: 'Lincoln', + }, + }, { + externalID: 'testID', + }] + }); + + expect(where).toEqual("((firstName='Abe' AND lastName='Lincoln' AND title='Mr. President') OR (owner.firstName='Abe' AND owner.lastName='Lincoln') OR (externalID='testID'))"); + }); + }); + describe('with OR min/max queries', () => { it('should create a valid nested OR min/max query', () => { const where = Where.toQuerySyntax({ From 0510f047075ca07d5e59d9b87de2a38d86a7352b Mon Sep 17 00:00:00 2001 From: Trent Hibbard Date: Thu, 29 Jul 2021 14:10:20 -0400 Subject: [PATCH 2/2] Switch docs to travis-ci.com from travis-ci.org and fix build --- .travis.yml | 1 - README.md | 2 +- docs/index.html | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2c87fd2..6595b82 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ notifications: node_js: - 10 before_install: - - sudo apt-get update - sudo apt-get install expect - sudo apt-get install libnotify-bin install: diff --git a/README.md b/README.md index 9afaf4f..b9ba0e9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ --- -[![Build Status](https://travis-ci.org/bullhorn/taurus.svg?branch=master)](https://travis-ci.org/bullhorn/taurus) +[![Build Status](https://travis-ci.com/bullhorn/taurus.svg?branch=master)](https://travis-ci.com/bullhorn/taurus) [![Dependency Status](https://dependencyci.com/github/bullhorn/taurus/badge)](https://dependencyci.com/github/bullhorn/taurus) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) [![npm version](https://badge.fury.io/js/%40bullhorn%2Ftaurus.svg)](https://badge.fury.io/js/%40bullhorn%2Ftaurus) diff --git a/docs/index.html b/docs/index.html index e8a0787..2dae857 100644 --- a/docs/index.html +++ b/docs/index.html @@ -69,7 +69,7 @@

Build Status: Linux Dependency Status XO code style +

Build Status: Linux Dependency Status XO code style npm version


WebsiteDocsBlog