preserver user selected order
This commit is contained in:
1 parent
1bc27789f3
commit
8e143b45d5
1 file changed
+19
-12
@@ -29,19 +29,13 @@ const createStatusPage = async (statusPageData, image) => {
|
|||||||
|
|
||||||
const getStatusPage = async () => {
|
const getStatusPage = async () => {
|
||||||
try {
|
try {
|
||||||
// const statusPage = await StatusPage.findOne();
|
|
||||||
// if (statusPage === null || statusPage === undefined) {
|
|
||||||
// const error = new Error(errorMessages.STATUS_PAGE_NOT_FOUND);
|
|
||||||
// error.status = 404;
|
|
||||||
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
// const ids = statusPage.monitors;
|
|
||||||
// const monitors = await Monitor.find({ _id: { $in: ids } }).lean();
|
|
||||||
// return { statusPage, monitors };
|
|
||||||
|
|
||||||
const statusPageQuery = await StatusPage.aggregate([
|
const statusPageQuery = await StatusPage.aggregate([
|
||||||
{ $limit: 1 },
|
{ $limit: 1 },
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
originalMonitors: "$monitors",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: "monitors",
|
from: "monitors",
|
||||||
@@ -69,6 +63,13 @@ const getStatusPage = async () => {
|
|||||||
as: "monitors.checks",
|
as: "monitors.checks",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$addFields: {
|
||||||
|
"monitors.orderIndex": {
|
||||||
|
$indexOfArray: ["$originalMonitors", "$monitors._id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
_id: "$_id",
|
_id: "$_id",
|
||||||
@@ -79,7 +80,12 @@ const getStatusPage = async () => {
|
|||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
statusPage: 1,
|
statusPage: 1,
|
||||||
monitors: 1,
|
monitors: {
|
||||||
|
$sortArray: {
|
||||||
|
input: "$monitors",
|
||||||
|
sortBy: { orderIndex: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@@ -90,6 +96,7 @@ const getStatusPage = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { statusPage, monitors } = statusPageQuery[0];
|
const { statusPage, monitors } = statusPageQuery[0];
|
||||||
|
|
||||||
const normalizedMonitors = monitors.map((monitor) => {
|
const normalizedMonitors = monitors.map((monitor) => {
|
||||||
return {
|
return {
|
||||||
...monitor,
|
...monitor,
|
||||||
|
|||||||
Reference in new issue
Block a user