Files
Checkmate/Server/db/mongo/modules/statusPageModule.js
T

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-11-11 12:16:34 +08:00
import StatusPage from "../../models/StatusPage.js";
import { errorMessages } from "../../../utils/messages.js";
const SERVICE_NAME = "statusPageModule";
const createStatusPage = async (statusPageData) => {
try {
const statusPage = new StatusPage({ ...statusPageData });
await statusPage.save();
return statusPage;
} catch (error) {
2024-11-11 14:39:30 +08:00
if (error?.code === 11000) {
// Handle duplicate URL errors
error.status = 400;
error.message = errorMessages.STATUS_PAGE_URL_NOT_UNIQUE;
}
2024-11-11 12:16:34 +08:00
error.service = SERVICE_NAME;
error.method = "createStatusPage";
throw error;
}
};
const getStatusPageByUrl = async (url) => {
try {
const statusPage = await StatusPage.findOne({ url });
if (statusPage === null || statusPage === undefined) {
const error = new Error(errorMessages.STATUS_PAGE_NOT_FOUND);
error.status = 404;
throw error;
}
return statusPage;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getStatusPageByUrl";
throw error;
}
};
2024-11-11 14:39:30 +08:00
export { createStatusPage, getStatusPageByUrl };