diff --git a/utilities/utils/helper.js b/utilities/utils/helper.js index b9c20a6f3..80b37ce27 100644 --- a/utilities/utils/helper.js +++ b/utilities/utils/helper.js @@ -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(); }