mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
Add functionality to get media meta
+ Remove unused code + Fix misspelling + Fix error handling to handle errors with no status code
This commit is contained in:
@@ -143,25 +143,27 @@ export const getAllMedia = async (req: Request, res: Response) => {
|
||||
res.status(200).json({
|
||||
type: "success",
|
||||
payload: {
|
||||
medias,
|
||||
media: medias,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
interface CreateMediaBody {
|
||||
description?: string;
|
||||
location?: string;
|
||||
export const getMediaMeta = async (req: Request, res: Response) => {
|
||||
const pid = req.params.pid;
|
||||
|
||||
events?: string[];
|
||||
disciplines?: string[];
|
||||
roles?: string[];
|
||||
}
|
||||
const meta = await prisma.media.findUnique({ where: { pid }, select: { pid: true, description: true } });
|
||||
|
||||
interface MediaParams {
|
||||
eventPid?: string;
|
||||
disciplinePid?: string;
|
||||
rolePid?: string;
|
||||
}
|
||||
if (!meta) {
|
||||
throw new NotFoundError("media", pid);
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
type: "success",
|
||||
payload: {
|
||||
meta,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteMedia = async (req: Request, res: Response) => {
|
||||
if (req.auth?.permission_level != "ELEVATED") {
|
||||
|
||||
@@ -67,7 +67,7 @@ export default function defaultErrorHandler(err: any, req: Request, res: Respons
|
||||
logger.error("--- Unhandled error ---");
|
||||
logger.error(err);
|
||||
|
||||
return res.status(err.status).json({
|
||||
return res.status(err.status || 500).json({
|
||||
type: "error",
|
||||
payload: {
|
||||
message: err.message,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import express from "express";
|
||||
import fileUpload from "express-fileupload";
|
||||
import { requireAuthentication } from "../Middleware/auth/auth";
|
||||
import { deleteMedia, getAllMedia, uploadImage } from "../Controllers/media.controller";
|
||||
import { deleteMedia, getAllMedia, getMediaMeta, uploadImage } from "../Controllers/media.controller";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -11,6 +11,7 @@ router.use("/", express.static("/app/media", { redirect: false }));
|
||||
router.post("/", requireAuthentication, fileUpload(), uploadImage);
|
||||
|
||||
router.get("/", requireAuthentication, getAllMedia); // Reading all files should be a senstive operation
|
||||
router.get("/:pid/meta", getMediaMeta);
|
||||
|
||||
router.delete("/:pid", requireAuthentication, deleteMedia);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user