de-duplicated (un-)linkMedia

This commit is contained in:
Laurin
2022-05-29 17:19:45 +02:00
parent 4f94bf074c
commit 1cb345c316
8 changed files with 120 additions and 215 deletions
-58
View File
@@ -123,61 +123,3 @@ export const createRoleSchema = async (
throw e;
}
};
interface visualParams {
schemaPid: string;
}
interface visualBody {
mediaPid: string;
}
export const addVisual = async (req: Request<visualParams, {}, visualBody>, res: Response) => {
if (req.auth?.permission_level != "ELEVATED") {
res.status(403).json(createInsufficientPermissionsError());
}
const { schemaPid } = req.params;
const schema = await prisma.roleSchema.update({
where: { pid: schemaPid },
data: {
visual: { connect: { pid: req.body.mediaPid } },
},
});
if (!schema) {
throw new NotFoundError("role_schema", schemaPid);
}
return res.status(200).json({
type: "success",
payload: {},
});
};
export const deleteVisual = async (req: Request<visualParams & { pid: string }>, res: Response) => {
if (req.auth?.permission_level != "ELEVATED") {
res.status(403).json(createInsufficientPermissionsError());
}
const { schemaPid, pid } = req.params;
try {
await prisma.roleSchema.update({
where: {
pid: schemaPid,
},
data: {
visual: { disconnect: { pid } },
},
});
return res.status(204).end();
} catch (e) {
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
throw new NotFoundError("role_schema", schemaPid);
}
throw e;
}
};