expressa 2.0.8 → 2.0.10
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 +27 -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
|
@@ -53,6 +53,19 @@ exports.validateSchema = function(collection, doc) {
|
|
|
53
53
|
return true
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
exports.getSchemaProperty = function(collection, path) {
|
|
57
|
+
const parts = path.split('.')
|
|
58
|
+
let obj = schemas[collection]
|
|
59
|
+
for (const part of parts) {
|
|
60
|
+
if (obj.properties && obj.properties[part]) {
|
|
61
|
+
obj = obj.properties[part]
|
|
62
|
+
} else {
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return obj
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
exports.orderBy = function (data, orderby) {
|
|
57
70
|
data.sort(function compare (a, b) {
|
|
58
71
|
for (let i = 0; i < orderby.length; i++) {
|
|
@@ -185,6 +198,20 @@ exports.mongoUpdate = function(doc, update) {
|
|
|
185
198
|
return mongoQuery(doc, {}, update)
|
|
186
199
|
}
|
|
187
200
|
|
|
201
|
+
exports.mongoToPostgres = mongoToPostgres
|
|
202
|
+
|
|
203
|
+
// paging requires orderby to include a field that is known to be unique and constant
|
|
204
|
+
// to ensure consistent results from database with offset and limit. Chosen field should
|
|
205
|
+
// also represent a preferred ordering when doing final sort
|
|
206
|
+
exports.orderByForPagedRequests = function(orderby, finalSortField = 'meta.created') {
|
|
207
|
+
orderby = exports.normalizeOrderBy(orderby || {})
|
|
208
|
+
const allFields = orderby.map(([field]) => field)
|
|
209
|
+
if (!allFields.includes(finalSortField)) {
|
|
210
|
+
orderby.push([finalSortField, 1])
|
|
211
|
+
}
|
|
212
|
+
return orderby
|
|
213
|
+
}
|
|
214
|
+
|
|
188
215
|
exports.normalizeOrderBy = function(orderby) {
|
|
189
216
|
if (Array.isArray(orderby)) {
|
|
190
217
|
orderby = orderby.map(function (ordering) {
|