import { InvestigationController } from "@controllers/investigation.controller";
import { asyncHandler } from "@utils/asyncHandler";
import { Router } from "express";
import { requireAuthenticated } from "middlewares/auth";
import { validateRequest } from "../middlewares/validateRequest";
import { CreateInvestigationSchema, DeleteInvestigationParamsSchema, GetFieldHistoryParamsSchema, GetFieldHistoryQuerySchema, GetInvestigationParamsSchema, GetInvestigationVersionsParamsSchema, GetInvestigationVersionsQuerySchema, GetInvestigationsQuerySchema, RegenerateOtherFieldsBodySchema, RegenerateOtherFieldsParamsSchema, ResolveContradictionBodySchema, ResolveContradictionParamsSchema, UpdateInvestigationParamsSchema, UpdateInvestigationSchema, } from "../schemas/investigation.validation";
/**
* REST endpoints that manage investigations.
* @category Routes
*/
const router = Router();
router.use(requireAuthenticated);
/**
* POST /api/investigation
* Create a new investigation
* @category Routes
*/
router.post("/", validateRequest({
body: CreateInvestigationSchema,
}), asyncHandler(InvestigationController.createInvestigation));
/**
* GET /api/investigation
* Get investigations with pagination
* @category Routes
*/
router.get("/", validateRequest({
query: GetInvestigationsQuerySchema,
}), asyncHandler(InvestigationController.getInvestigations));
/**
* GET /api/investigation/format
* Get investigation schema format
* @category Routes
*/
router.get("/format", InvestigationController.getInvestigationFormat);
/**
* GET /api/investigation/:id
* Get a single investigation by ID
* @category Routes
*/
router.get("/:id", validateRequest({
params: GetInvestigationParamsSchema,
}), asyncHandler(InvestigationController.getInvestigation));
/**
* PUT /api/investigation/:id
* Update an investigation
* @category Routes
*/
router.put("/:id", validateRequest({
params: UpdateInvestigationParamsSchema,
body: UpdateInvestigationSchema,
}), asyncHandler(InvestigationController.updateInvestigation));
/**
* DELETE /api/investigation/:id
* Permanently delete an investigation and its related chat history
* @category Routes
*/
router.delete("/:id", validateRequest({
params: DeleteInvestigationParamsSchema,
}), asyncHandler(InvestigationController.deleteInvestigation));
/**
* POST /api/investigation/:id/clone
* Clone an investigation
* @category Routes
*/
router.post("/:id/clone", validateRequest({
params: GetInvestigationParamsSchema,
}), asyncHandler(InvestigationController.cloneInvestigation));
/**
* GET /api/investigation/:id/field/:fieldPath/history
* Get history for a specific field
* @category Routes
*/
router.get("/:id/field/:fieldPath/history", validateRequest({
params: GetFieldHistoryParamsSchema,
query: GetFieldHistoryQuerySchema,
}), asyncHandler(InvestigationController.getFieldHistory));
router.get("/:id/versions", validateRequest({
params: GetInvestigationVersionsParamsSchema,
query: GetInvestigationVersionsQuerySchema,
}), asyncHandler(InvestigationController.getInvestigationVersions));
router.post("/:id/undo", validateRequest({
params: GetInvestigationParamsSchema,
}), asyncHandler(InvestigationController.undoInvestigation));
router.post("/:id/redo", validateRequest({
params: GetInvestigationParamsSchema,
}), asyncHandler(InvestigationController.redoInvestigation));
/**
* POST /api/investigation/:id/resolve-contradiction
* Resolve contradiction for a specific field in the investigation
* @category Routes
*/
router.post("/:id/resolve-contradiction", validateRequest({
params: ResolveContradictionParamsSchema,
body: ResolveContradictionBodySchema,
}), asyncHandler(InvestigationController.resolveContradiction));
/**
* POST /api/investigation/:id/regenerate-other-fields
* Regenerate other fields based on a specific field
* This operation does NOT save to chat history (not visible in chat)
* @category Routes
*/
router.post("/:id/regenerate-other-fields", validateRequest({
params: RegenerateOtherFieldsParamsSchema,
body: RegenerateOtherFieldsBodySchema,
}), asyncHandler(InvestigationController.regenerateOtherFields));
export { router as investigationRoutes };
Source