mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
[create-pull-request] push formatted files
This commit is contained in:
@@ -197,17 +197,17 @@ interface visualBody {
|
||||
}
|
||||
|
||||
export const addVisual = async (req: Request<visualParams, {}, visualBody>, res: Response) => {
|
||||
if (req.auth?.permission_level != "ELEVATED"){
|
||||
if (req.auth?.permission_level != "ELEVATED") {
|
||||
res.status(403).json(createInsufficientPermissionsError());
|
||||
}
|
||||
|
||||
const { disciplinePid } = req.params;
|
||||
|
||||
|
||||
const discipline = await prisma.discipline.update({
|
||||
where: { pid: disciplinePid },
|
||||
data: {
|
||||
visual: {connect: {pid: req.body.mediaPid}}
|
||||
}
|
||||
visual: { connect: { pid: req.body.mediaPid } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!discipline) {
|
||||
@@ -216,25 +216,25 @@ export const addVisual = async (req: Request<visualParams, {}, visualBody>, res:
|
||||
|
||||
return res.status(200).json({
|
||||
type: "success",
|
||||
payload: { }
|
||||
})
|
||||
payload: {},
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteVisual = async (req: Request<visualParams & { pid: string }>, res: Response) => {
|
||||
if (req.auth?.permission_level != "ELEVATED"){
|
||||
if (req.auth?.permission_level != "ELEVATED") {
|
||||
res.status(403).json(createInsufficientPermissionsError());
|
||||
}
|
||||
|
||||
const { disciplinePid, pid } = req.params;
|
||||
|
||||
try {
|
||||
await prisma.discipline.update({
|
||||
where: {
|
||||
await prisma.discipline.update({
|
||||
where: {
|
||||
pid: disciplinePid,
|
||||
},
|
||||
data: {
|
||||
visual: { disconnect: { pid } }
|
||||
}
|
||||
},
|
||||
data: {
|
||||
visual: { disconnect: { pid } },
|
||||
},
|
||||
});
|
||||
return res.status(204).end();
|
||||
} catch (e) {
|
||||
|
||||
@@ -52,7 +52,7 @@ export const getEvent = async (req: Request, res: Response) => {
|
||||
date: true,
|
||||
pid: true,
|
||||
id: false,
|
||||
visual: { select: { pid: true, description: true } }
|
||||
visual: { select: { pid: true, description: true } },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -100,14 +100,16 @@ export const addEvent = async (req: Request, res: Response) => {
|
||||
typeof req.body.name !== "string" ||
|
||||
typeof req.body.date !== "string" ||
|
||||
typeof req.body.briefDescription !== "string" ||
|
||||
req.body.fullDescription && typeof req.body.fullDescription !== "string"
|
||||
(req.body.fullDescription && typeof req.body.fullDescription !== "string")
|
||||
) {
|
||||
return res.status(400).json(generateInvalidBodyError({
|
||||
name: DataType.STRING,
|
||||
date: DataType.DATETIME,
|
||||
briefDescription: DataType.STRING,
|
||||
["fullDescription?"]: DataType.STRING,
|
||||
}));
|
||||
return res.status(400).json(
|
||||
generateInvalidBodyError({
|
||||
name: DataType.STRING,
|
||||
date: DataType.DATETIME,
|
||||
briefDescription: DataType.STRING,
|
||||
["fullDescription?"]: DataType.STRING,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
//TODO: Check if date is valid
|
||||
@@ -141,8 +143,8 @@ const EventBody = z.object({
|
||||
name: z.string(),
|
||||
date: z.string(),
|
||||
briefDescription: z.string(),
|
||||
fullDescription: z.string()
|
||||
})
|
||||
fullDescription: z.string(),
|
||||
});
|
||||
|
||||
const UpdateBody = EventBody.partial();
|
||||
|
||||
@@ -156,12 +158,14 @@ export const updateEvent = async (req: Request<{ pid: string }>, res: Response)
|
||||
const result = UpdateBody.safeParse(req.body);
|
||||
|
||||
if (result.success === false) {
|
||||
return res.status(400).json(generateInvalidBodyError({
|
||||
name: DataType.STRING,
|
||||
date: DataType.DATETIME,
|
||||
briefDescription: DataType.STRING,
|
||||
["fullDescription?"]: DataType.STRING,
|
||||
}));
|
||||
return res.status(400).json(
|
||||
generateInvalidBodyError({
|
||||
name: DataType.STRING,
|
||||
date: DataType.DATETIME,
|
||||
briefDescription: DataType.STRING,
|
||||
["fullDescription?"]: DataType.STRING,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const body = result.data;
|
||||
@@ -173,16 +177,16 @@ export const updateEvent = async (req: Request<{ pid: string }>, res: Response)
|
||||
name: body.name,
|
||||
date: body.date,
|
||||
briefDescription: body.briefDescription,
|
||||
fullDescription: body.fullDescription
|
||||
fullDescription: body.fullDescription,
|
||||
},
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
date: true,
|
||||
briefDescription: true,
|
||||
fullDescription: true
|
||||
}
|
||||
})
|
||||
fullDescription: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!event) {
|
||||
throw new NotFoundError("event", pid);
|
||||
@@ -191,7 +195,7 @@ export const updateEvent = async (req: Request<{ pid: string }>, res: Response)
|
||||
res.status(200).json({
|
||||
type: "success",
|
||||
payload: {
|
||||
event
|
||||
event,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -217,8 +221,7 @@ export const updateEvent = async (req: Request<{ pid: string }>, res: Response)
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
interface DeleteEventQueryParams {
|
||||
pid: string;
|
||||
@@ -269,8 +272,8 @@ export const addVisual = async (req: Request<visualParams, {}, visualBody>, res:
|
||||
const event = await prisma.event.update({
|
||||
where: { pid: eventPid },
|
||||
data: {
|
||||
visual: { connect: { pid: req.body.mediaPid } }
|
||||
}
|
||||
visual: { connect: { pid: req.body.mediaPid } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!event) {
|
||||
@@ -279,8 +282,8 @@ export const addVisual = async (req: Request<visualParams, {}, visualBody>, res:
|
||||
|
||||
return res.status(200).json({
|
||||
type: "success",
|
||||
payload: {}
|
||||
})
|
||||
payload: {},
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteVisual = async (req: Request<visualParams & { pid: string }>, res: Response) => {
|
||||
@@ -297,7 +300,7 @@ export const deleteVisual = async (req: Request<visualParams & { pid: string }>,
|
||||
},
|
||||
data: {
|
||||
visual: { disconnect: { pid } },
|
||||
}
|
||||
},
|
||||
});
|
||||
return res.status(204).end();
|
||||
} catch (e) {
|
||||
|
||||
@@ -132,9 +132,9 @@ export const getAllMedia = async (req: Request, res: Response) => {
|
||||
const medias = await prisma.media.findMany({
|
||||
select: {
|
||||
description: true,
|
||||
events: {select: {pid: true}},
|
||||
disciplines: {select: {pid: true}},
|
||||
roles: {select: {pid: true}},
|
||||
events: { select: { pid: true } },
|
||||
disciplines: { select: { pid: true } },
|
||||
roles: { select: { pid: true } },
|
||||
pid: true,
|
||||
id: false,
|
||||
},
|
||||
|
||||
@@ -133,17 +133,17 @@ interface visualBody {
|
||||
}
|
||||
|
||||
export const addVisual = async (req: Request<visualParams, {}, visualBody>, res: Response) => {
|
||||
if (req.auth?.permission_level != "ELEVATED"){
|
||||
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 } }
|
||||
}
|
||||
visual: { connect: { pid: req.body.mediaPid } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!schema) {
|
||||
@@ -152,25 +152,25 @@ export const addVisual = async (req: Request<visualParams, {}, visualBody>, res:
|
||||
|
||||
return res.status(200).json({
|
||||
type: "success",
|
||||
payload: { }
|
||||
})
|
||||
payload: {},
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteVisual = async (req: Request<visualParams & { pid: string}>, res: Response) => {
|
||||
if (req.auth?.permission_level != "ELEVATED"){
|
||||
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: {
|
||||
await prisma.roleSchema.update({
|
||||
where: {
|
||||
pid: schemaPid,
|
||||
},
|
||||
data: {
|
||||
visual: { disconnect: { pid } }
|
||||
}
|
||||
},
|
||||
data: {
|
||||
visual: { disconnect: { pid } },
|
||||
},
|
||||
});
|
||||
return res.status(204).end();
|
||||
} catch (e) {
|
||||
|
||||
@@ -18,9 +18,17 @@ router.get("/:pid", getDiscipline);
|
||||
|
||||
router.delete<"/:pid", { pid: string }>("/:pid", requireAuthentication, deleteDiscipline);
|
||||
|
||||
router.post<"/:disciplinePid/images", {disciplinePid: string}>("/:disciplinePid/images", requireAuthentication, addVisual);
|
||||
router.post<"/:disciplinePid/images", { disciplinePid: string }>(
|
||||
"/:disciplinePid/images",
|
||||
requireAuthentication,
|
||||
addVisual
|
||||
);
|
||||
|
||||
router.delete<"/:disciplinePid/images/:pid", {disciplinePid: string, pid: string}>("/:disciplinePid/images/:pid", requireAuthentication, deleteVisual);
|
||||
router.delete<"/:disciplinePid/images/:pid", { disciplinePid: string; pid: string }>(
|
||||
"/:disciplinePid/images/:pid",
|
||||
requireAuthentication,
|
||||
deleteVisual
|
||||
);
|
||||
|
||||
eventRouter.post("/:eventPid/disciplines", requireAuthentication, createDiscipline);
|
||||
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import Express from "express";
|
||||
import { string } from "zod";
|
||||
import { addEvent, addVisual, deleteEvent, deleteVisual, getAllEvents, getEvent, updateEvent } from "../Controllers/event.controller";
|
||||
import {
|
||||
addEvent,
|
||||
addVisual,
|
||||
deleteEvent,
|
||||
deleteVisual,
|
||||
getAllEvents,
|
||||
getEvent,
|
||||
updateEvent,
|
||||
} from "../Controllers/event.controller";
|
||||
import { requireAuthentication } from "../Middleware/auth/auth";
|
||||
const router = Express.Router();
|
||||
|
||||
|
||||
@@ -20,9 +20,12 @@ disciplineRouter.get("/:disciplinePid/role-schemas", getAllRoleSchemasWithParam)
|
||||
|
||||
disciplineRouter.post("/:disciplinePid/role-schemas", requireAuthentication, createRoleSchema);
|
||||
|
||||
router.post<"/:schemaPid/images", {schemaPid: string}>("/:schemaPid/images", requireAuthentication, addVisual);
|
||||
|
||||
router.delete<"/:schemaPid/images/:pid", {schemaPid: string, pid: string}>("/:schemaPid/images/:pid", requireAuthentication, deleteVisual);
|
||||
router.post<"/:schemaPid/images", { schemaPid: string }>("/:schemaPid/images", requireAuthentication, addVisual);
|
||||
|
||||
router.delete<"/:schemaPid/images/:pid", { schemaPid: string; pid: string }>(
|
||||
"/:schemaPid/images/:pid",
|
||||
requireAuthentication,
|
||||
deleteVisual
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user