Files
Checkmate/Server/controllers/statusPageController.js
T

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-11-11 12:17:06 +08:00
import { handleError, handleValidationError } from "./controllerUtils.js";
import {
createStatusPageBodyValidation,
getStatusPageParamValidation,
} from "../validation/joi.js";
import { successMessages } from "../utils/messages.js";
const SERVICE_NAME = "statusPageController";
2024-12-24 11:58:42 -08:00
class StatusPageController {
constructor(db) {
this.db = db;
2024-11-11 12:17:06 +08:00
}
2024-12-24 11:58:42 -08:00
createStatusPage = async (req, res, next) => {
try {
await createStatusPageBodyValidation.validateAsync(req.body);
} catch (error) {
next(handleValidationError(error, SERVICE_NAME));
return;
}
2024-11-11 12:17:06 +08:00
2024-12-24 11:58:42 -08:00
try {
const statusPage = await this.db.createStatusPage(req.body);
2025-01-20 11:02:55 -08:00
return res.success({
2024-12-24 11:58:42 -08:00
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;
}
2024-11-11 12:17:06 +08:00
2024-12-24 11:58:42 -08:00
try {
const { url } = req.params;
const statusPage = await this.db.getStatusPageByUrl(url);
2025-01-20 11:02:55 -08:00
return res.success({
2024-12-24 11:58:42 -08:00
msg: successMessages.STATUS_PAGE_BY_URL,
data: statusPage,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "getStatusPage"));
}
};
}
2024-11-11 12:17:06 +08:00
2024-12-24 11:58:42 -08:00
export default StatusPageController;