mirror of
https://github.com/detleph/server.git
synced 2026-09-05 07:56:21 +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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user