mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
modified event responses and updated discipline briefDescription + fullDescription
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
|
||||
import { Request, Response } from "express";
|
||||
import e, { Request, Response } from "express";
|
||||
import { z } from "zod";
|
||||
import prisma from "../lib/prisma";
|
||||
import NotFoundError from "../Middleware/error/NotFoundError";
|
||||
@@ -8,16 +8,39 @@ import { createInsufficientPermissionsError, DataType, generateError, generateIn
|
||||
|
||||
require("express-async-errors");
|
||||
|
||||
const EventBody = z.object({
|
||||
name: z.string(),
|
||||
date: z.string(),
|
||||
briefDescription: z.string(),
|
||||
fullDescription: z.string(),
|
||||
});
|
||||
|
||||
const UpdateBody = EventBody.partial();
|
||||
|
||||
const CreateEventBody = EventBody.partial({
|
||||
fullDescription: true,
|
||||
});
|
||||
|
||||
export const getAllEvents = async (req: Request, res: Response) => {
|
||||
const events = await prisma.event.findMany({
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
date: true,
|
||||
briefDescription: true,
|
||||
fullDescription: true,
|
||||
visual: { select: { pid: true, description: true } },
|
||||
date: true,
|
||||
pid: true,
|
||||
id: false,
|
||||
disciplines: {
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
}},
|
||||
organisations: {
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -46,13 +69,25 @@ export const getEvent = async (req: Request, res: Response) => {
|
||||
pid: eventId,
|
||||
},
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
date: true,
|
||||
briefDescription: true,
|
||||
fullDescription: true,
|
||||
date: true,
|
||||
pid: true,
|
||||
id: false,
|
||||
visual: { select: { pid: true, description: true } },
|
||||
disciplines: {
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
briefDescription: true,
|
||||
fullDescription: true,
|
||||
}},
|
||||
organisations: {
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -96,12 +131,10 @@ export const addEvent = async (req: Request, res: Response) => {
|
||||
if (req.auth?.permission_level !== "ELEVATED") {
|
||||
res.status(403).json(createInsufficientPermissionsError());
|
||||
}
|
||||
if (
|
||||
typeof req.body.name !== "string" ||
|
||||
typeof req.body.date !== "string" ||
|
||||
typeof req.body.briefDescription !== "string" ||
|
||||
(req.body.fullDescription && typeof req.body.fullDescription !== "string")
|
||||
) {
|
||||
|
||||
const result = CreateEventBody.safeParse(req.body);
|
||||
|
||||
if(result.success === false){
|
||||
return res.status(400).json(
|
||||
generateInvalidBodyError({
|
||||
name: DataType.STRING,
|
||||
@@ -122,10 +155,9 @@ export const addEvent = async (req: Request, res: Response) => {
|
||||
fullDescription: req.body.fullDescription,
|
||||
},
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
date: true,
|
||||
pid: true,
|
||||
id: false,
|
||||
briefDescription: true,
|
||||
fullDescription: true,
|
||||
},
|
||||
@@ -139,15 +171,6 @@ export const addEvent = async (req: Request, res: Response) => {
|
||||
});
|
||||
};
|
||||
|
||||
const EventBody = z.object({
|
||||
name: z.string(),
|
||||
date: z.string(),
|
||||
briefDescription: z.string(),
|
||||
fullDescription: z.string(),
|
||||
});
|
||||
|
||||
const UpdateBody = EventBody.partial();
|
||||
|
||||
export const updateEvent = async (req: Request<{ pid: string }>, res: Response) => {
|
||||
if (req.auth?.permission_level !== "ELEVATED") {
|
||||
res.status(403).json(createInsufficientPermissionsError());
|
||||
|
||||
Reference in New Issue
Block a user