Skip to content

Commit 74e5d65

Browse files
eljensojmdobry
authored andcommitted
Fixes #23 (#25)
1 parent 1a2901e commit 74e5d65

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/queryParser.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export function parseQuery (query) {
66
}
77
if (query.orderBy || query.sort) {
88
const orderBy = query.orderBy || query.sort
9-
if (orderBy.length) {
9+
if (Array.isArray(orderBy)) {
1010
query.orderBy = orderBy.map((clause) => {
11-
if (typeof clause === 'string') {
11+
if (typeof clause === 'string' && clause.indexOf('{') >= 0) {
1212
return JSON.parse(clause)
1313
}
1414
return clause
1515
})
16-
query.sort = undefined
1716
}
17+
query.sort = undefined
1818
}
1919
}
2020

test/queryParser.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ describe('queryParser', function () {
9191
})
9292
})
9393

94+
it('should use orderBy directly if orderBy is present as simple string', function () {
95+
const query = {
96+
orderBy: 'foo'
97+
}
98+
JSDataExpress.parseQuery(query)
99+
assert.deepEqual(query, {
100+
orderBy: 'foo',
101+
sort: undefined
102+
})
103+
})
104+
105+
it('should use orderBy directly if orderBy is present as array of strings', function () {
106+
const query = {
107+
orderBy: ['foo']
108+
}
109+
JSDataExpress.parseQuery(query)
110+
assert.deepEqual(query, {
111+
orderBy: ['foo'],
112+
sort: undefined
113+
})
114+
})
115+
94116
it('should not parse orderBy if orderby is present but is empty', function () {
95117
const query = {
96118
orderBy: []

0 commit comments

Comments
 (0)