add db method for getting status page by url, update delete method to delete by url

This commit is contained in:
Alex Holliday
2025-02-07 14:46:36 -08:00
parent 27e4bd006c
commit 65bc98ca2e
+21 -4
View File
@@ -47,10 +47,21 @@ const updateStatusPage = async (statusPageData, image) => {
}
};
const getStatusPageByUrl = async (url) => {
try {
const statusPage = await StatusPage.aggregate([{ $match: { url } }]);
return statusPage[0];
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getStatusPageByUrl";
throw error;
}
};
const getStatusPage = async () => {
try {
const statusPageQuery = await StatusPage.aggregate([
{ $limit: 1 },
{ $match: { url: "/status/public" } },
{
$set: {
originalMonitors: "$monitors",
@@ -143,9 +154,9 @@ const getStatusPage = async () => {
}
};
const deleteStatusPage = async () => {
const deleteStatusPage = async (url) => {
try {
await StatusPage.deleteOne({});
await StatusPage.deleteOne({ url });
} catch (error) {
error.service = SERVICE_NAME;
error.method = "createStatusPage";
@@ -153,4 +164,10 @@ const deleteStatusPage = async () => {
}
};
export { createStatusPage, updateStatusPage, getStatusPage, deleteStatusPage };
export {
createStatusPage,
updateStatusPage,
getStatusPage,
getStatusPageByUrl,
deleteStatusPage,
};