Merge pull request #1552 from bluewave-labs/hotfix/be/default-sort-order
hotfix: add a default sort order if a field to sort by is not specified
This commit is contained in:
1 file changed
+4
-2
@@ -501,7 +501,10 @@ const getMonitorsByTeamId = async (req) => {
|
|||||||
limit = parseInt(limit);
|
limit = parseInt(limit);
|
||||||
page = parseInt(page);
|
page = parseInt(page);
|
||||||
rowsPerPage = parseInt(rowsPerPage);
|
rowsPerPage = parseInt(rowsPerPage);
|
||||||
|
if (field === undefined) {
|
||||||
|
field = "name";
|
||||||
|
order = "asc";
|
||||||
|
}
|
||||||
// Build the match stage
|
// Build the match stage
|
||||||
const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) };
|
const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) };
|
||||||
if (type !== undefined) {
|
if (type !== undefined) {
|
||||||
@@ -511,7 +514,6 @@ const getMonitorsByTeamId = async (req) => {
|
|||||||
const skip = page && rowsPerPage ? page * rowsPerPage : 0;
|
const skip = page && rowsPerPage ? page * rowsPerPage : 0;
|
||||||
|
|
||||||
const sort = { [field]: order === "asc" ? 1 : -1 };
|
const sort = { [field]: order === "asc" ? 1 : -1 };
|
||||||
|
|
||||||
const results = await Monitor.aggregate([
|
const results = await Monitor.aggregate([
|
||||||
{ $match: matchStage },
|
{ $match: matchStage },
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user