mirror of
https://github.com/detleph/server.git
synced 2026-09-07 23:44:40 +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 { Admin } from "@prisma/client";
|
||||||
import { PrismaClientUnknownRequestError } from "@prisma/client/runtime";
|
import { PrismaClientKnownRequestError, PrismaClientUnknownRequestError } from "@prisma/client/runtime";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import prisma from "../lib/prisma";
|
import prisma from "../lib/prisma";
|
||||||
import { generateError, genericError, handleCreateByName } from "./common";
|
import { createInsufficientPermissionsError, generateError, genericError, handleCreateByName } from "./common";
|
||||||
|
|
||||||
const basicGroup = {
|
const basicGroup = {
|
||||||
pid: true,
|
pid: true,
|
||||||
@@ -114,3 +114,27 @@ export const createGroup = async (req: Request<{ organisationPid: string }, {},
|
|||||||
res
|
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 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 { requireAuthentication } from "../Middleware/auth/auth";
|
||||||
import organisationRouter from "./organisation.routes";
|
import organisationRouter from "./organisation.routes";
|
||||||
|
|
||||||
@@ -7,6 +13,7 @@ const router = express.Router();
|
|||||||
|
|
||||||
router.get("/", getAllGroups);
|
router.get("/", getAllGroups);
|
||||||
router.get("/:pid", getGroup);
|
router.get("/:pid", getGroup);
|
||||||
|
router.delete<"/:pid", { pid: string }>("/:pid", requireAuthentication, deleteGroup);
|
||||||
|
|
||||||
organisationRouter.get("/:organisationPid/groups", getAllGroupsWithParam);
|
organisationRouter.get("/:organisationPid/groups", getAllGroupsWithParam);
|
||||||
organisationRouter.post("/:organisationPid/groups", requireAuthentication, createGroup);
|
organisationRouter.post("/:organisationPid/groups", requireAuthentication, createGroup);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import express from "express";
|
|||||||
import eventRouter from "./event.routes";
|
import eventRouter from "./event.routes";
|
||||||
import {
|
import {
|
||||||
createOrganisation,
|
createOrganisation,
|
||||||
|
deleteOrganisation,
|
||||||
getAllOrganisations,
|
getAllOrganisations,
|
||||||
getAllOrganisationsWithParam,
|
getAllOrganisationsWithParam,
|
||||||
getOrganisation,
|
getOrganisation,
|
||||||
@@ -14,6 +15,7 @@ const router = express.Router();
|
|||||||
router.get("/", getAllOrganisations);
|
router.get("/", getAllOrganisations);
|
||||||
router.get("/:pid", getOrganisation);
|
router.get("/:pid", getOrganisation);
|
||||||
router.put<"/:pid", { pid: string }>("/:pid", requireAuthentication, updateOrganisation);
|
router.put<"/:pid", { pid: string }>("/:pid", requireAuthentication, updateOrganisation);
|
||||||
|
router.delete<"/:pid", { pid: string }>("/:pid", requireAuthentication, deleteOrganisation);
|
||||||
|
|
||||||
eventRouter.get("/:eventPid/organisations", getAllOrganisationsWithParam);
|
eventRouter.get("/:eventPid/organisations", getAllOrganisationsWithParam);
|
||||||
eventRouter.post<"/:eventPid/organisations", { eventPid: string }>(
|
eventRouter.post<"/:eventPid/organisations", { eventPid: string }>(
|
||||||
|
|||||||
Reference in New Issue
Block a user