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

52 lines
1.6 KiB
TypeScript
Raw Normal View History

2026-02-24 23:20:36 +00:00
import { Request, Response, NextFunction } from "express";
2026-03-01 17:35:00 +00:00
import { getChecksParamValidation, getChecksQueryValidation } from "@/validation/checkValidation.js";
2026-02-24 23:20:36 +00:00
import type { IGeoChecksService } from "@/service/business/geoChecksService.js";
2026-03-20 10:59:34 -07:00
import { requireTeamId } from "./controllerUtils.js";
import { AppError } from "@/utils/AppError.js";
2026-02-24 23:20:36 +00:00
const SERVICE_NAME = "geoCheckController";
2026-03-20 11:51:17 -07:00
export interface IGeoCheckController {
getGeoChecksByMonitor: (req: Request, res: Response, next: NextFunction) => Promise<Response | void>;
}
class GeoCheckController implements IGeoCheckController {
2026-02-24 23:20:36 +00:00
static SERVICE_NAME = SERVICE_NAME;
private geoChecksService: IGeoChecksService;
constructor(geoChecksService: IGeoChecksService) {
this.geoChecksService = geoChecksService;
}
get serviceName() {
return GeoCheckController.SERVICE_NAME;
}
getGeoChecksByMonitor = async (req: Request, res: Response, next: NextFunction) => {
try {
2026-03-20 10:59:34 -07:00
const validatedParams = getChecksParamValidation.parse(req.params);
const validatedQuery = getChecksQueryValidation.parse(req.query);
const teamId = requireTeamId(req.user?.teamId);
2026-02-24 23:20:36 +00:00
const result = await this.geoChecksService.getGeoChecksByMonitor({
2026-03-20 10:59:34 -07:00
monitorId: validatedParams.monitorId,
teamId: teamId,
sortOrder: validatedQuery.sortOrder,
dateRange: validatedQuery.dateRange,
page: validatedQuery.page,
rowsPerPage: validatedQuery.rowsPerPage,
continent: validatedQuery.continent,
2026-02-24 23:20:36 +00:00
});
return res.status(200).json({
success: true,
msg: "Geo checks retrieved successfully",
data: result,
});
} catch (error) {
next(error);
}
};
}
export default GeoCheckController;