mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
modified event responses and updated discipline briefDescription + fullDescription
This commit is contained in:
@@ -21,6 +21,8 @@ const basicDiscipline = {
|
||||
visual: { select: { pid: true } },
|
||||
maxTeamSize: true,
|
||||
minTeamSize: true,
|
||||
briefDescription: true,
|
||||
fullDescription: true,
|
||||
event: { select: { pid: true, name: true } },
|
||||
roles: { select: { pid: true, name: true } },
|
||||
} as const;
|
||||
@@ -117,6 +119,8 @@ interface CreateDisciplineBody {
|
||||
name?: string;
|
||||
minTeamSize?: number;
|
||||
maxTeamSize?: number;
|
||||
briefDescription: string;
|
||||
fullDescription: string;
|
||||
}
|
||||
|
||||
// require: auth(ELEVATED)
|
||||
@@ -126,9 +130,14 @@ export const createDiscipline = async (req: Request<{ eventPid: string }, {}, Cr
|
||||
return res.status(403).json(createInsufficientPermissionsError());
|
||||
}
|
||||
|
||||
const { name, minTeamSize, maxTeamSize } = req.body;
|
||||
const { name, minTeamSize, maxTeamSize, briefDescription, fullDescription } = req.body;
|
||||
|
||||
if (typeof name !== "string" || typeof minTeamSize !== "number" || typeof maxTeamSize !== "number") {
|
||||
if (typeof name !== "string" ||
|
||||
typeof minTeamSize !== "number" ||
|
||||
typeof maxTeamSize !== "number" ||
|
||||
typeof briefDescription !== "string" ||
|
||||
(fullDescription && typeof fullDescription !== "string")
|
||||
) {
|
||||
return res.status(400).json(
|
||||
generateInvalidBodyError({
|
||||
name: DataType.STRING,
|
||||
@@ -144,7 +153,7 @@ export const createDiscipline = async (req: Request<{ eventPid: string }, {}, Cr
|
||||
|
||||
try {
|
||||
const discipline = await prisma.discipline.create({
|
||||
data: { name, minTeamSize, maxTeamSize, event: { connect: { pid: req.params.eventPid } } },
|
||||
data: { name, minTeamSize, maxTeamSize, briefDescription, fullDescription, event: { connect: { pid: req.params.eventPid } } },
|
||||
select: {
|
||||
pid: true,
|
||||
name: true,
|
||||
|
||||
@@ -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