Updated the project.ts route

This commit is contained in:
Mathias Wagner 2023-07-31 20:04:48 +02:00
parent 19878760cb
commit 7c7abd7c21
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -7,7 +7,7 @@ import {
patchProject,
regenerateKey,
} from "@controller/projects";
import { validateSchema } from "@utils/error";
import { sendError, validateSchema } from "@utils/error";
import { patchProjectValidation, projectCreationValidation } from "./validations/project";
const app: Router = Router();
@ -42,6 +42,9 @@ app.delete("/:id", async (req: Request, res: Response) => {
app.patch("/:id", async (req: Request, res: Response) => {
if (validateSchema(res, patchProjectValidation, req.body)) return;
if (Object.keys(req.body).length === 0)
return sendError(res, 400, 4, "You need to provide at least one field to update");
const patchError = await patchProject(req.params.id, String(req.user?._id), req.body);
if (patchError) return res.json(patchError);