expressa 2.0.8 → 2.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/collections.js +1 -1
- package/modules/admin/package.json +1 -1
- package/package.json +1 -1
- package/util.js +12 -0
|
@@ -101,7 +101,7 @@ exports.get = async function (req) {
|
|
|
101
101
|
}
|
|
102
102
|
req.query.pageitems = parseInt(req.query.pageitems) || parseInt(req.query.limit) || 10
|
|
103
103
|
req.query.offset = util.getDatabaseOffset(req.query.page, req.query.pageitems)
|
|
104
|
-
req.query.orderby = req.query.orderby
|
|
104
|
+
req.query.orderby = util.orderByForPagedRequests(req.query.orderby)
|
|
105
105
|
delete req.query.limit
|
|
106
106
|
delete req.query.skip
|
|
107
107
|
let pageData, totalItems
|
package/package.json
CHANGED
package/util.js
CHANGED
|
@@ -185,6 +185,18 @@ exports.mongoUpdate = function(doc, update) {
|
|
|
185
185
|
return mongoQuery(doc, {}, update)
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
// paging requires orderby to include a field that is known to be unique and constant
|
|
189
|
+
// to ensure consistent results from database with offset and limit. Chosen field should
|
|
190
|
+
// also represent a preferred ordering when doing final sort
|
|
191
|
+
exports.orderByForPagedRequests = function(orderby, finalSortField = 'meta.created') {
|
|
192
|
+
orderby = exports.normalizeOrderBy(orderby || {})
|
|
193
|
+
const allFields = orderby.map(([field]) => field)
|
|
194
|
+
if (!allFields.includes(finalSortField)) {
|
|
195
|
+
orderby.push([finalSortField, 1])
|
|
196
|
+
}
|
|
197
|
+
return orderby
|
|
198
|
+
}
|
|
199
|
+
|
|
188
200
|
exports.normalizeOrderBy = function(orderby) {
|
|
189
201
|
if (Array.isArray(orderby)) {
|
|
190
202
|
orderby = orderby.map(function (ordering) {
|