mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
Add router to delete groups
+ Add route to delete organisations
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Admin } from "@prisma/client";
|
||||
import { PrismaClientUnknownRequestError } from "@prisma/client/runtime";
|
||||
import { PrismaClientKnownRequestError, PrismaClientUnknownRequestError } from "@prisma/client/runtime";
|
||||
import { Request, Response } from "express";
|
||||
import prisma from "../lib/prisma";
|
||||
import { generateError, genericError, handleCreateByName } from "./common";
|
||||
import { createInsufficientPermissionsError, generateError, genericError, handleCreateByName } from "./common";
|
||||
|
||||
const basicGroup = {
|
||||
pid: true,
|
||||
@@ -114,3 +114,27 @@ export const createGroup = async (req: Request<{ organisationPid: string }, {},
|
||||
res
|
||||
);
|
||||
};
|
||||
|
||||
interface DeleteGroupQueryParams {
|
||||
pid: string;
|
||||
}
|
||||
|
||||
export const deleteGroup = async (req: Request<DeleteGroupQueryParams>, res: Response) => {
|
||||
if (req.auth?.permission_level !== "ELEVATED") {
|
||||
return res.status(403).json(createInsufficientPermissionsError());
|
||||
}
|
||||
|
||||
const { pid } = req.params;
|
||||
|
||||
try {
|
||||
prisma.group.delete({ where: { pid } });
|
||||
|
||||
return res.status(204).end();
|
||||
} catch (e) {
|
||||
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
|
||||
return res.status(404).json(generateError(`The group with the ID ${pid} could not be found`));
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import express from "express";
|
||||
import { createGroup, getAllGroups, getAllGroupsWithParam, getGroup } from "../Controllers/group.controllers";
|
||||
import {
|
||||
createGroup,
|
||||
deleteGroup,
|
||||
getAllGroups,
|
||||
getAllGroupsWithParam,
|
||||
getGroup,
|
||||
} from "../Controllers/group.controllers";
|
||||
import { requireAuthentication } from "../Middleware/auth/auth";
|
||||
import organisationRouter from "./organisation.routes";
|
||||
|
||||
@@ -7,6 +13,7 @@ const router = express.Router();
|
||||
|
||||
router.get("/", getAllGroups);
|
||||
router.get("/:pid", getGroup);
|
||||
router.delete<"/:pid", { pid: string }>("/:pid", requireAuthentication, deleteGroup);
|
||||
|
||||
organisationRouter.get("/:organisationPid/groups", getAllGroupsWithParam);
|
||||
organisationRouter.post("/:organisationPid/groups", requireAuthentication, createGroup);
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from "express";
|
||||
import eventRouter from "./event.routes";
|
||||
import {
|
||||
createOrganisation,
|
||||
deleteOrganisation,
|
||||
getAllOrganisations,
|
||||
getAllOrganisationsWithParam,
|
||||
getOrganisation,
|
||||
@@ -14,6 +15,7 @@ const router = express.Router();
|
||||
router.get("/", getAllOrganisations);
|
||||
router.get("/:pid", getOrganisation);
|
||||
router.put<"/:pid", { pid: string }>("/:pid", requireAuthentication, updateOrganisation);
|
||||
router.delete<"/:pid", { pid: string }>("/:pid", requireAuthentication, deleteOrganisation);
|
||||
|
||||
eventRouter.get("/:eventPid/organisations", getAllOrganisationsWithParam);
|
||||
eventRouter.post<"/:eventPid/organisations", { eventPid: string }>(
|
||||
|
||||
Reference in New Issue
Block a user