mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
Add endpoint to delete disciplines
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Prisma, Organisation, Admin, AdminLevel, Team } from "@prisma/client";
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
|
||||
import { PrismaClientKnownRequestError, PrismaClientUnknownRequestError } from "@prisma/client/runtime";
|
||||
import { Request, Response } from "express";
|
||||
import prisma from "../lib/prisma";
|
||||
import ForwardableError from "../Middleware/error/ForwardableError";
|
||||
@@ -162,3 +162,28 @@ export const createDiscipline = async (req: Request<{ eventPid: string }, {}, Cr
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
interface DeleteDisciplineQueryParams {
|
||||
pid: string;
|
||||
}
|
||||
|
||||
// requires: auth(ELEVATED)
|
||||
export const deleteDiscipline = async (req: Request<DeleteDisciplineQueryParams>, res: Response) => {
|
||||
if (req.auth?.permission_level !== "ELEVATED") {
|
||||
res.status(403).json(createInsufficientPermissionsError());
|
||||
}
|
||||
|
||||
const { pid } = req.params;
|
||||
|
||||
try {
|
||||
await prisma.discipline.delete({ where: { pid } });
|
||||
|
||||
return res.status(204).end();
|
||||
} catch (e) {
|
||||
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
|
||||
throw new NotFoundError("discipline", pid);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import express from "express";
|
||||
import eventRouter from "./event.routes";
|
||||
import { createDiscipline, getAllDisciplines, getDiscipline } from "../Controllers/discipline.controller";
|
||||
import {
|
||||
createDiscipline,
|
||||
deleteDiscipline,
|
||||
getAllDisciplines,
|
||||
getDiscipline,
|
||||
} from "../Controllers/discipline.controller";
|
||||
import { requireAuthentication } from "../Middleware/auth/auth";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", getAllDisciplines); // TODO: Optional auth
|
||||
router.get("/:pid", getDiscipline);
|
||||
router.delete<"/:pid", { pid: string }>("/:pid", requireAuthentication, deleteDiscipline);
|
||||
|
||||
eventRouter.post("/:eventPid/disciplines", requireAuthentication, createDiscipline);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user