mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
de-duplicated (un-)linkMedia
This commit is contained in:
@@ -272,67 +272,3 @@ export const deleteEvent = async (req: Request<DeleteEventQueryParams>, res: Res
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
// REVIEW: This code **will** need to be de-duplicated
|
||||
|
||||
interface visualParams {
|
||||
eventPid: 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 { eventPid } = req.params;
|
||||
|
||||
if (typeof req.body.mediaPid !== "string") {
|
||||
res.status(400).json(generateInvalidBodyError({ mediaPid: DataType.STRING }));
|
||||
}
|
||||
|
||||
const event = await prisma.event.update({
|
||||
where: { pid: eventPid },
|
||||
data: {
|
||||
visual: { connect: { pid: req.body.mediaPid } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!event) {
|
||||
throw new NotFoundError("event", eventPid);
|
||||
}
|
||||
|
||||
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 { eventPid, pid } = req.params;
|
||||
|
||||
try {
|
||||
await prisma.event.update({
|
||||
where: {
|
||||
pid: eventPid,
|
||||
},
|
||||
data: {
|
||||
visual: { disconnect: { pid } },
|
||||
},
|
||||
});
|
||||
return res.status(204).end();
|
||||
} catch (e) {
|
||||
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
|
||||
throw new NotFoundError("discipline", eventPid);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user