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