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:
@@ -37,6 +37,8 @@ model Discipline {
|
|||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||||
name String
|
name String
|
||||||
|
briefDescription String
|
||||||
|
fullDescription String?
|
||||||
minTeamSize Int
|
minTeamSize Int
|
||||||
maxTeamSize Int
|
maxTeamSize Int
|
||||||
|
|
||||||
@@ -121,7 +123,7 @@ model Group {
|
|||||||
model Media {
|
model Media {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
pid String @unique
|
pid String @unique
|
||||||
description String
|
description String @default("visual")
|
||||||
|
|
||||||
events Event[]
|
events Event[]
|
||||||
disciplines Discipline[]
|
disciplines Discipline[]
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ const basicDiscipline = {
|
|||||||
visual: { select: { pid: true } },
|
visual: { select: { pid: true } },
|
||||||
maxTeamSize: true,
|
maxTeamSize: true,
|
||||||
minTeamSize: true,
|
minTeamSize: true,
|
||||||
|
briefDescription: true,
|
||||||
|
fullDescription: true,
|
||||||
event: { select: { pid: true, name: true } },
|
event: { select: { pid: true, name: true } },
|
||||||
roles: { select: { pid: true, name: true } },
|
roles: { select: { pid: true, name: true } },
|
||||||
} as const;
|
} as const;
|
||||||
@@ -117,6 +119,8 @@ interface CreateDisciplineBody {
|
|||||||
name?: string;
|
name?: string;
|
||||||
minTeamSize?: number;
|
minTeamSize?: number;
|
||||||
maxTeamSize?: number;
|
maxTeamSize?: number;
|
||||||
|
briefDescription: string;
|
||||||
|
fullDescription: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// require: auth(ELEVATED)
|
// require: auth(ELEVATED)
|
||||||
@@ -126,9 +130,14 @@ export const createDiscipline = async (req: Request<{ eventPid: string }, {}, Cr
|
|||||||
return res.status(403).json(createInsufficientPermissionsError());
|
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(
|
return res.status(400).json(
|
||||||
generateInvalidBodyError({
|
generateInvalidBodyError({
|
||||||
name: DataType.STRING,
|
name: DataType.STRING,
|
||||||
@@ -144,7 +153,7 @@ export const createDiscipline = async (req: Request<{ eventPid: string }, {}, Cr
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const discipline = await prisma.discipline.create({
|
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: {
|
select: {
|
||||||
pid: true,
|
pid: true,
|
||||||
name: true,
|
name: true,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
|
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
|
||||||
import { Request, Response } from "express";
|
import e, { Request, Response } from "express";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import prisma from "../lib/prisma";
|
import prisma from "../lib/prisma";
|
||||||
import NotFoundError from "../Middleware/error/NotFoundError";
|
import NotFoundError from "../Middleware/error/NotFoundError";
|
||||||
@@ -8,16 +8,39 @@ import { createInsufficientPermissionsError, DataType, generateError, generateIn
|
|||||||
|
|
||||||
require("express-async-errors");
|
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) => {
|
export const getAllEvents = async (req: Request, res: Response) => {
|
||||||
const events = await prisma.event.findMany({
|
const events = await prisma.event.findMany({
|
||||||
select: {
|
select: {
|
||||||
|
pid: true,
|
||||||
name: true,
|
name: true,
|
||||||
|
date: true,
|
||||||
briefDescription: true,
|
briefDescription: true,
|
||||||
fullDescription: true,
|
fullDescription: true,
|
||||||
visual: { select: { pid: true, description: true } },
|
visual: { select: { pid: true, description: true } },
|
||||||
date: true,
|
disciplines: {
|
||||||
|
select: {
|
||||||
pid: true,
|
pid: true,
|
||||||
id: false,
|
name: true,
|
||||||
|
}},
|
||||||
|
organisations: {
|
||||||
|
select: {
|
||||||
|
pid: true,
|
||||||
|
name: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -46,13 +69,25 @@ export const getEvent = async (req: Request, res: Response) => {
|
|||||||
pid: eventId,
|
pid: eventId,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
pid: true,
|
||||||
|
name: true,
|
||||||
|
date: true,
|
||||||
|
briefDescription: true,
|
||||||
|
fullDescription: true,
|
||||||
|
visual: { select: { pid: true, description: true } },
|
||||||
|
disciplines: {
|
||||||
|
select: {
|
||||||
|
pid: true,
|
||||||
name: true,
|
name: true,
|
||||||
briefDescription: true,
|
briefDescription: true,
|
||||||
fullDescription: true,
|
fullDescription: true,
|
||||||
date: true,
|
}},
|
||||||
|
organisations: {
|
||||||
|
select: {
|
||||||
pid: true,
|
pid: true,
|
||||||
id: false,
|
name: true,
|
||||||
visual: { select: { pid: true, description: true } },
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -96,12 +131,10 @@ export const addEvent = async (req: Request, res: Response) => {
|
|||||||
if (req.auth?.permission_level !== "ELEVATED") {
|
if (req.auth?.permission_level !== "ELEVATED") {
|
||||||
res.status(403).json(createInsufficientPermissionsError());
|
res.status(403).json(createInsufficientPermissionsError());
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
typeof req.body.name !== "string" ||
|
const result = CreateEventBody.safeParse(req.body);
|
||||||
typeof req.body.date !== "string" ||
|
|
||||||
typeof req.body.briefDescription !== "string" ||
|
if(result.success === false){
|
||||||
(req.body.fullDescription && typeof req.body.fullDescription !== "string")
|
|
||||||
) {
|
|
||||||
return res.status(400).json(
|
return res.status(400).json(
|
||||||
generateInvalidBodyError({
|
generateInvalidBodyError({
|
||||||
name: DataType.STRING,
|
name: DataType.STRING,
|
||||||
@@ -122,10 +155,9 @@ export const addEvent = async (req: Request, res: Response) => {
|
|||||||
fullDescription: req.body.fullDescription,
|
fullDescription: req.body.fullDescription,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
pid: true,
|
||||||
name: true,
|
name: true,
|
||||||
date: true,
|
date: true,
|
||||||
pid: true,
|
|
||||||
id: false,
|
|
||||||
briefDescription: true,
|
briefDescription: true,
|
||||||
fullDescription: 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) => {
|
export const updateEvent = async (req: Request<{ 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());
|
||||||
|
|||||||
Reference in New Issue
Block a user