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

107 lines
2.6 KiB
TypeScript
Raw Normal View History

2026-01-20 18:56:06 +00:00
import { AppError } from "@/utils/AppError.js";
2026-01-09 15:44:11 -08:00
import { Request, Response, NextFunction } from "express";
2026-01-21 10:15:13 -08:00
import { requireTeamId } from "./controllerUtils.js";
2026-01-09 15:44:11 -08:00
const SERVICE_NAME = "incidentController";
class IncidentController {
static SERVICE_NAME = SERVICE_NAME;
private incidentService: any;
constructor(incidentService: any) {
this.incidentService = incidentService;
}
get serviceName() {
return IncidentController.SERVICE_NAME;
}
getIncidentsByTeam = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-01-21 10:15:13 -08:00
const { sortOrder, dateRange, page, rowsPerPage, status, monitorId, resolutionType } = req.query || {};
const teamId = requireTeamId(req.user?.teamId);
const result = await this.incidentService.getIncidentsByTeam(
teamId,
sortOrder,
dateRange,
page,
rowsPerPage,
status,
monitorId,
resolutionType
);
2026-01-09 15:44:11 -08:00
return res.status(200).json({
success: true,
msg: "Incidents retrieved successfully",
data: result,
});
} catch (error) {
next(error);
}
};
getIncidentSummary = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-01-20 18:56:06 +00:00
const teamId = req.user?.teamId;
if (!teamId) {
throw new AppError({ message: "Team ID is required", service: SERVICE_NAME, status: 400 });
}
const limit = req.query.limit ? parseInt(req.query.limit as string, 10) : 10;
const summary = await this.incidentService.getIncidentSummary(req?.user?.teamId, limit);
2026-01-09 15:44:11 -08:00
return res.status(200).json({
success: true,
msg: "Incident summary retrieved successfully",
data: summary,
});
} catch (error) {
next(error);
}
};
getIncidentById = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-01-22 21:28:28 +00:00
const teamId = requireTeamId(req.user?.teamId);
const incidentId = req.params.incidentId;
if (!incidentId) {
throw new AppError({ message: "Incident ID is required", service: SERVICE_NAME, status: 400 });
}
const incident = await this.incidentService.getIncidentById(incidentId, teamId);
2026-01-09 15:44:11 -08:00
return res.status(200).json({
success: true,
msg: "Incident retrieved successfully",
data: incident,
});
} catch (error) {
next(error);
}
};
resolveIncidentManually = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-01-19 23:41:24 +00:00
const resolvedIncident = await this.incidentService.resolveIncident(
req?.params?.incidentId,
req?.user?.id,
req?.user?.teamId,
req?.body?.comment
);
2026-01-09 15:44:11 -08:00
return res.status(200).json({
success: true,
msg: "Incident resolved successfully",
data: resolvedIncident,
});
} catch (error) {
next(error);
}
};
}
export default IncidentController;