Skip to content

Commit 4cb53d4

Browse files
Merge pull request #280 from daostack/support_not_in
support scheme - not_in queries
2 parents 5f663f1 + 1e2345f commit 4cb53d4

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/client",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "",
55
"keywords": [],
66
"main": "dist/lib/index.js",

src/scheme.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,15 @@ export class Scheme implements IStateful<ISchemeState> {
9898
if (key === 'address' || key === 'dao') {
9999
const option = options.where[key] as string
100100
isAddress(option)
101-
options.where[key] = option.toLowerCase()
101+
options.where[key] = `"${option.toLowerCase()}"`
102+
} else if (key.endsWith('_in') || key.endsWith('_not_in')) {
103+
const option = options.where[key] as string[]
104+
options.where[key] = JSON.stringify(option)
105+
} else {
106+
const option = options.where[key] as string
107+
options.where[key] = `"${option}"`
102108
}
103-
104-
where += `${key}: "${options.where[key] as string}"\n`
109+
where += `${key}: ${options.where[key] as string}\n`
105110
}
106111

107112
const query = gql`{
@@ -113,7 +118,7 @@ export class Scheme implements IStateful<ISchemeState> {
113118
dao { id }
114119
paramsHash
115120
}
116-
}`
121+
} `
117122
const itemMap = (item: any): Scheme|null => {
118123
if (!options.where) { options.where = {}}
119124

@@ -173,7 +178,7 @@ export class Scheme implements IStateful<ISchemeState> {
173178

174179
public state(): Observable < ISchemeState > {
175180
const query = gql`
176-
{
181+
{
177182
controllerScheme (id: "${this.id}") {
178183
id
179184
address
@@ -256,7 +261,7 @@ export class Scheme implements IStateful<ISchemeState> {
256261
}
257262
}
258263
}
259-
`
264+
`
260265

261266
const itemMap = (item: any): ISchemeState|null => {
262267
if (!item) {
@@ -323,7 +328,7 @@ export class Scheme implements IStateful<ISchemeState> {
323328
break
324329

325330
default:
326-
msg = `Unknown proposal scheme: "${state.name}"`
331+
msg = `Unknown proposal scheme: '${state.name}'`
327332
throw Error(msg)
328333
}
329334

test/scheme.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Scheme', () => {
2626
expect(scheme).toBeInstanceOf(Scheme)
2727
})
2828

29-
it('Scheme are searchable', async () => {
29+
it('Schemes are searchable', async () => {
3030
const dao = await getTestDAO()
3131
let result: Scheme[]
3232
result = await Scheme.search(arc, {where: {dao: dao.id, name_not: null}})
@@ -64,7 +64,13 @@ describe('Scheme', () => {
6464
result = await Scheme.search(arc, {where: {dao: dao.id, name: 'SchemeRegistrar'}})
6565
.pipe(first()).toPromise()
6666
expect(result.length).toEqual(1)
67-
})
67+
result = await Scheme.search(arc, {where: {dao: dao.id, name_in: ['SchemeRegistrar', 'GenericScheme']}})
68+
.pipe(first()).toPromise()
69+
expect(result.length).toEqual(2)
70+
result = await Scheme.search(arc, {where: {dao: dao.id, name_not_in: ['GenericScheme']}})
71+
.pipe(first()).toPromise()
72+
expect(result.length).toBeGreaterThan(1)
73+
})
6874

6975
it('Scheme.state() is working for SchemeRegistrar schemes', async () => {
7076
const dao = await getTestDAO()

0 commit comments

Comments
 (0)