mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-14 13:49:40 -06:00
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
import { handleError, handleValidationError } from "./controllerUtils.js";
|
|
import {
|
|
createStatusPageBodyValidation,
|
|
getStatusPageParamValidation,
|
|
} from "../validation/joi.js";
|
|
import { successMessages } from "../utils/messages.js";
|
|
|
|
const SERVICE_NAME = "statusPageController";
|
|
|
|
class StatusPageController {
|
|
constructor(db) {
|
|
this.db = db;
|
|
}
|
|
|
|
createStatusPage = async (req, res, next) => {
|
|
try {
|
|
await createStatusPageBodyValidation.validateAsync(req.body);
|
|
} catch (error) {
|
|
next(handleValidationError(error, SERVICE_NAME));
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const statusPage = await this.db.createStatusPage(req.body);
|
|
return res.success({
|
|
msg: successMessages.STATUS_PAGE_CREATE,
|
|
data: statusPage,
|
|
});
|
|
} catch (error) {
|
|
next(handleError(error, SERVICE_NAME, "createStatusPage"));
|
|
}
|
|
};
|
|
getStatusPageByUrl = async (req, res, next) => {
|
|
try {
|
|
await getStatusPageParamValidation.validateAsync(req.params);
|
|
} catch (error) {
|
|
next(handleValidationError(error, SERVICE_NAME));
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const { url } = req.params;
|
|
const statusPage = await this.db.getStatusPageByUrl(url);
|
|
return res.success({
|
|
msg: successMessages.STATUS_PAGE_BY_URL,
|
|
data: statusPage,
|
|
});
|
|
} catch (error) {
|
|
next(handleError(error, SERVICE_NAME, "getStatusPage"));
|
|
}
|
|
};
|
|
}
|
|
|
|
export default StatusPageController;
|