Files
Checkmate/server/src/controllers/checkController.ts
T

132 lines
3.2 KiB
TypeScript
Raw Normal View History

2026-01-09 15:53:53 -08:00
import { Request, Response, NextFunction } from "express";
import {
getChecksParamValidation,
getChecksQueryValidation,
getTeamChecksQueryValidation,
deleteChecksParamValidation,
deleteChecksByTeamIdParamValidation,
updateChecksTTLBodyValidation,
2026-03-01 17:35:00 +00:00
} from "@/validation/checkValidation.js";
2026-01-09 15:53:53 -08:00
const SERVICE_NAME = "checkController";
class CheckController {
static SERVICE_NAME = SERVICE_NAME;
private checkService: any;
constructor(checkService: any) {
this.checkService = checkService;
}
get serviceName() {
return CheckController.SERVICE_NAME;
}
getChecksByMonitor = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-03-02 17:29:48 +00:00
getChecksParamValidation.parse(req.params);
getChecksQueryValidation.parse(req.query);
2026-01-09 15:53:53 -08:00
const result = await this.checkService.getChecksByMonitor({
monitorId: req?.params?.monitorId,
query: req?.query,
teamId: req?.user?.teamId,
});
return res.status(200).json({
success: true,
msg: "Checks retrieved successfully",
data: result,
});
} catch (error) {
next(error);
}
};
getChecksByTeam = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-03-02 17:29:48 +00:00
getTeamChecksQueryValidation.parse(req.query);
2026-01-09 15:53:53 -08:00
const checkData = await this.checkService.getChecksByTeam({
teamId: req?.user?.teamId,
query: req?.query,
});
return res.status(200).json({
success: true,
msg: "Team checks retrieved successfully",
data: checkData,
});
} catch (error) {
next(error);
}
};
getChecksSummaryByTeamId = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-01-27 20:46:28 +00:00
const dateRange = req.query?.dateRange || "hour";
const summary = await this.checkService.getChecksSummaryByTeamId({ teamId: req?.user?.teamId, dateRange });
2026-01-09 15:53:53 -08:00
return res.status(200).json({
success: true,
msg: "Checks summary retrieved successfully",
data: summary,
});
} catch (error) {
next(error);
}
};
deleteChecks = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-03-02 17:29:48 +00:00
deleteChecksParamValidation.parse(req.params);
2026-01-09 15:53:53 -08:00
const deletedCount = await this.checkService.deleteChecks({
2026-01-27 21:54:20 +00:00
monitorId: req.params.monitorId as string,
2026-01-09 15:53:53 -08:00
teamId: req?.user?.teamId,
});
return res.status(200).json({
success: true,
msg: "Checks deleted successfully",
data: { deletedCount },
});
} catch (error) {
next(error);
}
};
deleteChecksByTeamId = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-03-02 17:29:48 +00:00
deleteChecksByTeamIdParamValidation.parse(req.params);
2026-01-09 15:53:53 -08:00
const deletedCount = await this.checkService.deleteChecksByTeamId({ teamId: req?.user?.teamId });
return res.status(200).json({
success: true,
msg: "Checks deleted successfully",
data: { deletedCount },
});
} catch (error) {
next(error);
}
};
updateChecksTTL = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-03-02 17:29:48 +00:00
updateChecksTTLBodyValidation.parse(req.body);
2026-01-09 15:53:53 -08:00
await this.checkService.updateChecksTTL({
teamId: req?.user?.teamId,
ttl: req?.body?.ttl,
});
return res.status(200).json({
success: true,
msg: "Checks TTL updated successfully",
});
} catch (error) {
next(error);
}
};
}
export default CheckController;