Add /project/:id/leave route

This commit is contained in:
Mathias Wagner
2024-07-22 22:18:34 +02:00
parent 8ec90dd3f3
commit 7a977b5744

View File

@ -9,6 +9,7 @@ import {
} from "@controller/projects"; } from "@controller/projects";
import { sendError, validateSchema } from "@utils/error"; import { sendError, validateSchema } from "@utils/error";
import { patchProjectValidation, projectCreationValidation } from "./validations/project"; import { patchProjectValidation, projectCreationValidation } from "./validations/project";
import {leaveProject} from "@controller/member";
const app: Router = Router(); const app: Router = Router();
@ -39,6 +40,13 @@ app.delete("/:id", async (req: Request, res: Response) => {
res.json({ message: "The project has been successfully deleted" }); res.json({ message: "The project has been successfully deleted" });
}); });
app.post("/:id/leave", async (req: Request, res: Response) => {
const leaveError = await leaveProject(String(req.user?._id), req.params.id);
if (leaveError) return res.json(leaveError);
res.json({ message: "You have successfully left the project" });
});
app.patch("/:id", async (req: Request, res: Response) => { app.patch("/:id", async (req: Request, res: Response) => {
if (validateSchema(res, patchProjectValidation, req.body)) return; if (validateSchema(res, patchProjectValidation, req.body)) return;