File tree 2 files changed +25
-3
lines changed
2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -6,15 +6,15 @@ export function parseQuery (query) {
6
6
}
7
7
if ( query . orderBy || query . sort ) {
8
8
const orderBy = query . orderBy || query . sort
9
- if ( orderBy . length ) {
9
+ if ( Array . isArray ( orderBy ) ) {
10
10
query . orderBy = orderBy . map ( ( clause ) => {
11
- if ( typeof clause === 'string' ) {
11
+ if ( typeof clause === 'string' && clause . indexOf ( '{' ) >= 0 ) {
12
12
return JSON . parse ( clause )
13
13
}
14
14
return clause
15
15
} )
16
- query . sort = undefined
17
16
}
17
+ query . sort = undefined
18
18
}
19
19
}
20
20
Original file line number Diff line number Diff line change @@ -91,6 +91,28 @@ describe('queryParser', function () {
91
91
} )
92
92
} )
93
93
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
+
94
116
it ( 'should not parse orderBy if orderby is present but is empty' , function ( ) {
95
117
const query = {
96
118
orderBy : [ ]
You can’t perform that action at this time.
0 commit comments