feat(assist): 2 levels sort support

This commit is contained in:
Taha Yassine Kraiem 2022-07-15 16:02:55 +02:00 committed by Shekar Siri
parent 2de128ebcf
commit bb8dee83fe

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();
}