Merge pull request #613

v1.7.0 enhanced
This commit is contained in:
Kraiem Taha Yassine 2022-07-15 16:08:05 +02:00 committed by GitHub
commit 43686b1e41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -158,11 +158,17 @@ const getValue = function (obj, key) {
const sortPaginate = function (list, filters) {
const total = list.length;
list.sort((a, b) => {
const vA = getValue(a, filters.sort.key || "timestamp");
const vB = getValue(b, filters.sort.key || "timestamp");
return vA > vB ? 1 : vA < vB ? -1 : 0;
const tA = getValue(a, "timestamp");
const tB = getValue(b, "timestamp");
return tA > tB ? 1 : tA < tB ? -1 : 0;
});
if ((filters.sort.key || "timestamp") !== "timestamp") {
list.sort((a, b) => {
const vA = getValue(a, filters.sort.key);
const vB = getValue(b, filters.sort.key);
return vA > vB ? 1 : vA < vB ? -1 : 0;
});
}
if (filters.sort.order) {
list.reverse();
}