mirror of
https://github.com/detleph/server.git
synced 2026-09-06 23:44:26 +02:00
bug fixes in Discipline, Roleschema, Event & Media
This commit is contained in:
Generated
+2584
-101
File diff suppressed because it is too large
Load Diff
@@ -220,12 +220,12 @@ export const addVisual = async (req: Request<visualParams, {}, visualBody>, res:
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteVisual = async (req: Request<visualParams, {}, visualBody>, res: Response) => {
|
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());
|
res.status(403).json(createInsufficientPermissionsError());
|
||||||
}
|
}
|
||||||
|
|
||||||
const { disciplinePid } = req.params;
|
const { disciplinePid, pid } = req.params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prisma.discipline.update({
|
await prisma.discipline.update({
|
||||||
@@ -233,7 +233,7 @@ export const deleteVisual = async (req: Request<visualParams, {}, visualBody>, r
|
|||||||
pid: disciplinePid,
|
pid: disciplinePid,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
visual: { disconnect: { pid: req.body.mediaPid } }
|
visual: { disconnect: { pid } }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res.status(204).end();
|
return res.status(204).end();
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import prisma from "../lib/prisma";
|
|||||||
import NotFoundError from "../Middleware/error/NotFoundError";
|
import NotFoundError from "../Middleware/error/NotFoundError";
|
||||||
import { createInsufficientPermissionsError, DataType, generateError, generateInvalidBodyError } from "./common";
|
import { createInsufficientPermissionsError, DataType, generateError, generateInvalidBodyError } from "./common";
|
||||||
|
|
||||||
|
require("express-async-errors");
|
||||||
|
|
||||||
export const getAllEvents = async (req: Request, res: Response) => {
|
export const getAllEvents = async (req: Request, res: Response) => {
|
||||||
const events = await prisma.event.findMany({
|
const events = await prisma.event.findMany({
|
||||||
select: {
|
select: {
|
||||||
@@ -53,6 +55,10 @@ export const getEvent = async (req: Request, res: Response) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
throw new NotFoundError("event", eventId);
|
||||||
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
type: "success",
|
type: "success",
|
||||||
payload: {
|
payload: {
|
||||||
@@ -61,7 +67,7 @@ export const getEvent = async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||||
res.status(500).json({
|
return res.status(500).json({
|
||||||
type: "error",
|
type: "error",
|
||||||
payload: {
|
payload: {
|
||||||
message: `Internal Server error occured. Try again later`,
|
message: `Internal Server error occured. Try again later`,
|
||||||
@@ -70,7 +76,7 @@ export const getEvent = async (req: Request, res: Response) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e instanceof Prisma.PrismaClientUnknownRequestError) {
|
if (e instanceof Prisma.PrismaClientUnknownRequestError) {
|
||||||
res.status(500).json({
|
return res.status(500).json({
|
||||||
type: "error",
|
type: "error",
|
||||||
payload: {
|
payload: {
|
||||||
message: "Unknown error occurred with your request. Check if your parameters are correct",
|
message: "Unknown error occurred with your request. Check if your parameters are correct",
|
||||||
@@ -81,6 +87,8 @@ export const getEvent = async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,14 +100,15 @@ export const addEvent = async (req: Request, res: Response) => {
|
|||||||
if (
|
if (
|
||||||
typeof req.body.name !== "string" ||
|
typeof req.body.name !== "string" ||
|
||||||
typeof req.body.date !== "string" ||
|
typeof req.body.date !== "string" ||
|
||||||
typeof req.body.description !== "string" ||
|
typeof req.body.briefDescription !== "string" ||
|
||||||
req.body.fullDescription && req.body.fullDescription !== "string"
|
req.body.fullDescription && typeof req.body.fullDescription !== "string"
|
||||||
) {
|
) {
|
||||||
generateInvalidBodyError({
|
return res.status(400).json(generateInvalidBodyError({
|
||||||
name: DataType.STRING,
|
name: DataType.STRING,
|
||||||
date: DataType.DATETIME,
|
date: DataType.DATETIME,
|
||||||
description: DataType.STRING,
|
briefDescription: DataType.STRING,
|
||||||
});
|
["fullDescription?"]: DataType.STRING,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Check if date is valid
|
//TODO: Check if date is valid
|
||||||
@@ -108,7 +117,8 @@ export const addEvent = async (req: Request, res: Response) => {
|
|||||||
data: {
|
data: {
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
date: req.body.date,
|
date: req.body.date,
|
||||||
briefDescription: req.body.description,
|
briefDescription: req.body.briefDescription,
|
||||||
|
fullDescription: req.body.fullDescription,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
name: true,
|
name: true,
|
||||||
@@ -133,7 +143,7 @@ interface DeleteEventQueryParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// requires: auth(ELEVATED)
|
// requires: auth(ELEVATED)
|
||||||
export const deleteEvent = (req: Request<DeleteEventQueryParams>, res: Response) => {
|
export const deleteEvent = async (req: Request<DeleteEventQueryParams>, res: Response) => {
|
||||||
if (req.auth?.permission_level !== "ELEVATED") {
|
if (req.auth?.permission_level !== "ELEVATED") {
|
||||||
res.status(403).json(createInsufficientPermissionsError());
|
res.status(403).json(createInsufficientPermissionsError());
|
||||||
}
|
}
|
||||||
@@ -141,7 +151,7 @@ export const deleteEvent = (req: Request<DeleteEventQueryParams>, res: Response)
|
|||||||
const { pid } = req.params;
|
const { pid } = req.params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
prisma.event.delete({ where: { pid } });
|
await prisma.event.delete({ where: { pid } });
|
||||||
|
|
||||||
return res.status(204).end();
|
return res.status(204).end();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -191,12 +201,12 @@ export const addVisual = async (req: Request<visualParams, {}, visualBody>, res:
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteVisual = async (req: Request<visualParams, {}, visualBody>, res: Response) => {
|
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());
|
res.status(403).json(createInsufficientPermissionsError());
|
||||||
}
|
}
|
||||||
|
|
||||||
const { eventPid } = req.params;
|
const { eventPid, pid } = req.params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prisma.event.update({
|
await prisma.event.update({
|
||||||
@@ -204,7 +214,7 @@ export const deleteVisual = async (req: Request<visualParams, {}, visualBody>, r
|
|||||||
pid: eventPid,
|
pid: eventPid,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
visual: { disconnect: { pid: req.body.mediaPid } }
|
visual: { disconnect: { pid } },
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res.status(204).end();
|
return res.status(204).end();
|
||||||
|
|||||||
@@ -132,9 +132,9 @@ export const getAllMedia = async (req: Request, res: Response) => {
|
|||||||
const medias = await prisma.media.findMany({
|
const medias = await prisma.media.findMany({
|
||||||
select: {
|
select: {
|
||||||
description: true,
|
description: true,
|
||||||
events: true,
|
events: {select: {pid: true}},
|
||||||
disciplines: true,
|
disciplines: {select: {pid: true}},
|
||||||
roles: true,
|
roles: {select: {pid: true}},
|
||||||
pid: true,
|
pid: true,
|
||||||
id: false,
|
id: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -156,12 +156,12 @@ export const addVisual = async (req: Request<visualParams, {}, visualBody>, res:
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteVisual = async (req: Request<visualParams, {}, visualBody>, res: Response) => {
|
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());
|
res.status(403).json(createInsufficientPermissionsError());
|
||||||
}
|
}
|
||||||
|
|
||||||
const { schemaPid } = req.params;
|
const { schemaPid, pid } = req.params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prisma.roleSchema.update({
|
await prisma.roleSchema.update({
|
||||||
@@ -169,7 +169,7 @@ export const deleteVisual = async (req: Request<visualParams, {}, visualBody>, r
|
|||||||
pid: schemaPid,
|
pid: schemaPid,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
visual: { disconnect: { pid: req.body.mediaPid } }
|
visual: { disconnect: { pid } }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res.status(204).end();
|
return res.status(204).end();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Express from "express";
|
import Express from "express";
|
||||||
import { string } from "zod";
|
import { string } from "zod";
|
||||||
import { addEvent, addVisual, deleteVisual, getAllEvents, getEvent } from "../Controllers/event.controller";
|
import { addEvent, addVisual, deleteEvent, deleteVisual, getAllEvents, getEvent } from "../Controllers/event.controller";
|
||||||
import { requireAuthentication } from "../Middleware/auth/auth";
|
import { requireAuthentication } from "../Middleware/auth/auth";
|
||||||
const router = Express.Router();
|
const router = Express.Router();
|
||||||
|
|
||||||
@@ -10,6 +10,8 @@ router.get("/:eventId", getEvent);
|
|||||||
|
|
||||||
router.post("/", requireAuthentication, addEvent);
|
router.post("/", requireAuthentication, addEvent);
|
||||||
|
|
||||||
|
router.delete<"/:pid/", { pid: string }>("/:pid/", requireAuthentication, deleteEvent);
|
||||||
|
|
||||||
router.post<"/:eventPid/media", { eventPid: string }>("/:eventPid/media", requireAuthentication, addVisual);
|
router.post<"/:eventPid/media", { eventPid: string }>("/:eventPid/media", requireAuthentication, addVisual);
|
||||||
|
|
||||||
router.delete<"/:eventPid/media/:pid", { eventPid: string; pid: string }>(
|
router.delete<"/:eventPid/media/:pid", { eventPid: string; pid: string }>(
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import express from "express";
|
|||||||
import fileUpload from "express-fileupload";
|
import fileUpload from "express-fileupload";
|
||||||
import { requireAuthentication } from "../Middleware/auth/auth";
|
import { requireAuthentication } from "../Middleware/auth/auth";
|
||||||
import { deleteMedia, getAllMedia, getMediaMeta, uploadImage } from "../Controllers/media.controller";
|
import { deleteMedia, getAllMedia, getMediaMeta, uploadImage } from "../Controllers/media.controller";
|
||||||
|
import eventRouter from "./event.routes";
|
||||||
|
import disciplineRouter from "./discipline.routes";
|
||||||
|
import roleSchemaRouter from "./role_schema.routes";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -11,6 +14,7 @@ router.use("/", express.static("/app/media", { redirect: false }));
|
|||||||
router.post("/", requireAuthentication, fileUpload(), uploadImage);
|
router.post("/", requireAuthentication, fileUpload(), uploadImage);
|
||||||
|
|
||||||
router.get("/", requireAuthentication, getAllMedia); // Reading all files should be a senstive operation
|
router.get("/", requireAuthentication, getAllMedia); // Reading all files should be a senstive operation
|
||||||
|
|
||||||
router.get("/:pid/meta", getMediaMeta);
|
router.get("/:pid/meta", getMediaMeta);
|
||||||
|
|
||||||
router.delete("/:pid", requireAuthentication, deleteMedia);
|
router.delete("/:pid", requireAuthentication, deleteMedia);
|
||||||
|
|||||||
Reference in New Issue
Block a user