add db method for getting status page by url, update delete method to delete by url
This commit is contained in:
1 parent
27e4bd006c
commit
65bc98ca2e
1 file changed
+21
-4
@@ -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 () => {
|
const getStatusPage = async () => {
|
||||||
try {
|
try {
|
||||||
const statusPageQuery = await StatusPage.aggregate([
|
const statusPageQuery = await StatusPage.aggregate([
|
||||||
{ $limit: 1 },
|
{ $match: { url: "/status/public" } },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
originalMonitors: "$monitors",
|
originalMonitors: "$monitors",
|
||||||
@@ -143,9 +154,9 @@ const getStatusPage = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteStatusPage = async () => {
|
const deleteStatusPage = async (url) => {
|
||||||
try {
|
try {
|
||||||
await StatusPage.deleteOne({});
|
await StatusPage.deleteOne({ url });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.method = "createStatusPage";
|
error.method = "createStatusPage";
|
||||||
@@ -153,4 +164,10 @@ const deleteStatusPage = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { createStatusPage, updateStatusPage, getStatusPage, deleteStatusPage };
|
export {
|
||||||
|
createStatusPage,
|
||||||
|
updateStatusPage,
|
||||||
|
getStatusPage,
|
||||||
|
getStatusPageByUrl,
|
||||||
|
deleteStatusPage,
|
||||||
|
};
|
||||||
Reference in new issue
Block a user