Skip to content

Commit c0d0daa

Browse files
Neeraj SirdeshmukhNeeraj Sirdeshmukh
authored andcommitted
sortby and collections parameters in next link
1 parent 7e1bc13 commit c0d0daa

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.0] - 2022-06-01
9+
10+
### Changed
11+
12+
- Modified sortby and collections parameters in nextlink
13+
814
## [0.5.0] - 2022-05-20
915

1016
### Changed

src/lib/api.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,23 @@ const buildPaginationLinks = function (limit, parameters, bbox, intersects, endp
409409
const dictToURI = (dict) => (
410410
Object.keys(dict).map(
411411
(p) => {
412-
// const query = encodeURIComponent(dict[p])
413412
let value = dict[p]
414413
if (typeof value === 'object' && value !== null) {
415-
value = JSON.stringify(value)
414+
if (p === 'sortby') {
415+
const sortFields = []
416+
for (let i = 0; i < value.length; i += 1) {
417+
if (value[i]['direction'] === 'asc') {
418+
sortFields.push(value[i]['field'])
419+
} else {
420+
sortFields.push('-'.concat(value[i]['field']))
421+
}
422+
}
423+
value = sortFields.join(',')
424+
} else {
425+
value = JSON.stringify(value)
426+
}
416427
}
417428
const query = encodeURIComponent(value)
418-
if (p === 'collections') {
419-
return `${encodeURIComponent(p)}[]=${query}`
420-
}
421429
return `${encodeURIComponent(p)}=${query}`
422430
}
423431
).join('&')

0 commit comments

Comments
 (0)