Files
Checkmate/Server/controllers/statusPageController.js
T

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-11-11 12:17:06 +08:00
import { handleError, handleValidationError } from "./controllerUtils.js";
import {
createStatusPageBodyValidation,
getStatusPageParamValidation,
2025-02-03 15:06:25 -08:00
imageValidation,
2024-11-11 12:17:06 +08:00
} 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);
2025-02-03 15:06:25 -08:00
await imageValidation.validateAsync(req.file);
2024-12-24 11:58:42 -08:00
} 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 {
2025-02-03 15:06:25 -08:00
const statusPage = await this.db.createStatusPage(req.body, req.file);
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"));
}
};
2025-02-03 15:06:25 -08:00
getStatusPage = async (req, res, next) => {
2024-12-24 11:58:42 -08:00
try {
2025-02-03 15:06:25 -08:00
const statusPage = await this.db.getStatusPage();
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;