mirror of
https://github.com/detleph/server.git
synced 2026-09-04 00:26:03 +02:00
added deleteRoleSchema
This commit is contained in:
@@ -9,6 +9,7 @@ import SchemaError from "../Middleware/error/SchemaError";
|
|||||||
import {
|
import {
|
||||||
createInsufficientPermissionsError,
|
createInsufficientPermissionsError,
|
||||||
DataType,
|
DataType,
|
||||||
|
generateError,
|
||||||
generateInvalidBodyError,
|
generateInvalidBodyError,
|
||||||
NAME_ERROR,
|
NAME_ERROR,
|
||||||
validateName,
|
validateName,
|
||||||
@@ -197,6 +198,25 @@ export const updateRoleSchema = async (req: Request<{ pid: string }>, res: Respo
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deleteRoleSchema = async (req: Request<{ pid: string }>, res: Response) => {
|
||||||
|
if (req.auth?.permission_level !== "ELEVATED") {
|
||||||
|
res.status(403).json(createInsufficientPermissionsError());
|
||||||
|
}
|
||||||
|
|
||||||
|
const { pid } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await prisma.roleSchema.delete({ where: { pid } });
|
||||||
|
|
||||||
|
return res.status(204).end();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
|
||||||
|
return res.status(404).json(generateError(`The RoleSchema with the ID ${pid} could not be found`));
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
interface visualParams {
|
interface visualParams {
|
||||||
schemaPid: string;
|
schemaPid: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user