mirror of
https://github.com/detleph/server.git
synced 2026-09-04 00:26:03 +02:00
[create-pull-request] push formatted files
This commit is contained in:
@@ -29,7 +29,9 @@ export const getAllAdmins = async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add exception handling
|
// TODO: Add exception handling
|
||||||
const users = await prisma.admin.findMany({ select: { pid: true, name: true, permission_level: true, groups: { select: { pid: true } } } });
|
const users = await prisma.admin.findMany({
|
||||||
|
select: { pid: true, name: true, permission_level: true, groups: { select: { pid: true } } },
|
||||||
|
});
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
|||||||
@@ -168,7 +168,14 @@ 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, briefDescription, fullDescription, event: { connect: { pid: req.params.eventPid } } },
|
data: {
|
||||||
|
name,
|
||||||
|
minTeamSize,
|
||||||
|
maxTeamSize,
|
||||||
|
briefDescription,
|
||||||
|
fullDescription,
|
||||||
|
event: { connect: { pid: req.params.eventPid } },
|
||||||
|
},
|
||||||
select: basicDiscipline,
|
select: basicDiscipline,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const detailedGroup = {
|
|||||||
organisation: { select: { pid: true, name: true } },
|
organisation: { select: { pid: true, name: true } },
|
||||||
participants: { select: { pid: true, firstName: true, lastName: true } },
|
participants: { select: { pid: true, firstName: true, lastName: true } },
|
||||||
admins: { select: { pid: true, name: true } },
|
admins: { select: { pid: true, name: true } },
|
||||||
}
|
};
|
||||||
|
|
||||||
export const _getAllGroups = async (res: Response, organisationId: string | undefined) => {
|
export const _getAllGroups = async (res: Response, organisationId: string | undefined) => {
|
||||||
const groups = await prisma.group.findMany({
|
const groups = await prisma.group.findMany({
|
||||||
|
|||||||
@@ -224,7 +224,6 @@ export const linkMedia = async (req: Request<{ pid: string }, {}, { mediaPid: st
|
|||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const unlinkMedia = async (req: Request<{ pid: string; mediaPid: string }>, res: Response) => {
|
export const unlinkMedia = async (req: Request<{ pid: string; mediaPid: string }>, res: Response) => {
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ export const createParticipant = async (req: Request<{ teamPid: string }>, res:
|
|||||||
try {
|
try {
|
||||||
const discipline = await prisma.team.findUnique({
|
const discipline = await prisma.team.findUnique({
|
||||||
where: { pid: teamPid },
|
where: { pid: teamPid },
|
||||||
select: { discipline: true }
|
select: { discipline: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
const maxteamsize = discipline?.discipline.maxTeamSize;
|
const maxteamsize = discipline?.discipline.maxTeamSize;
|
||||||
|
|
||||||
const userCount = await prisma.participant.count({
|
const userCount = await prisma.participant.count({
|
||||||
where: { team: { pid: teamPid } }
|
where: { team: { pid: teamPid } },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (maxteamsize == userCount) {
|
if (maxteamsize == userCount) {
|
||||||
@@ -88,7 +88,7 @@ export const createParticipant = async (req: Request<{ teamPid: string }>, res:
|
|||||||
select: returnedParticipant,
|
select: returnedParticipant,
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(201).json({ type: "success", payload: { participant }, });
|
return res.status(201).json({ type: "success", payload: { participant } });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
|
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
|
||||||
return res
|
return res
|
||||||
@@ -176,9 +176,7 @@ export const deleteParticipant = async (req: Request<{ pid: string }>, res: Resp
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function getGroupByParticipantPid(partPid: string) {
|
export async function getGroupByParticipantPid(partPid: string) {
|
||||||
const parti = (
|
const parti = (await prisma.participant.findUnique({ where: { pid: partPid }, select: { group: true } }))?.group.pid;
|
||||||
await prisma.participant.findUnique({ where: { pid: partPid }, select: { group: true } })
|
|
||||||
)?.group.pid;
|
|
||||||
|
|
||||||
if (!parti) {
|
if (!parti) {
|
||||||
throw new NotFoundError("participant", partPid);
|
throw new NotFoundError("participant", partPid);
|
||||||
|
|||||||
@@ -106,7 +106,11 @@ export async function assignParticipantToRole(req: Request<{ pid: string }>, res
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const schema = await prisma.role.update({ where: { pid }, data: { participant: { connect: { pid: participantPid } } }, select: detailedRole });
|
const schema = await prisma.role.update({
|
||||||
|
where: { pid },
|
||||||
|
data: { participant: { connect: { pid: participantPid } } },
|
||||||
|
select: detailedRole,
|
||||||
|
});
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export const deleteTeam = async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.auth?.permission_level == "STANDARD") {
|
if (req.auth?.permission_level == "STANDARD") {
|
||||||
throw new AuthError("STANDARD Admins are not allowed to delete Teams!")
|
throw new AuthError("STANDARD Admins are not allowed to delete Teams!");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -137,7 +137,7 @@ export const deleteTeam = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
export async function checkTeamExistence(teamPid: string) {
|
export async function checkTeamExistence(teamPid: string) {
|
||||||
const teamCount = await prisma.team.count({
|
const teamCount = await prisma.team.count({
|
||||||
where: { pid: teamPid, }
|
where: { pid: teamPid },
|
||||||
});
|
});
|
||||||
if (teamCount == 0) {
|
if (teamCount == 0) {
|
||||||
throw new NotFoundError("team", teamPid);
|
throw new NotFoundError("team", teamPid);
|
||||||
@@ -145,13 +145,14 @@ export async function checkTeamExistence(teamPid: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroupsByTeamPid(teamPid: string) {
|
export async function getGroupsByTeamPid(teamPid: string) {
|
||||||
const team = (
|
const team = await prisma.team.findUnique({
|
||||||
await prisma.team.findUnique({ where: { pid: teamPid }, select: { participants: { select: { group: true } } } })
|
where: { pid: teamPid },
|
||||||
);
|
select: { participants: { select: { group: true } } },
|
||||||
|
});
|
||||||
|
|
||||||
let groups: string[] = [];
|
let groups: string[] = [];
|
||||||
|
|
||||||
team?.participants.forEach(participant => {
|
team?.participants.forEach((participant) => {
|
||||||
groups.push(participant.group.pid);
|
groups.push(participant.group.pid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ export function requireResponsibleForGroups(auth: AuthJWTPayload | undefined, gr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(groupPids)) {
|
if (Array.isArray(groupPids)) {
|
||||||
groupPids.forEach(gr => {
|
groupPids.forEach((gr) => {
|
||||||
if (auth?.groups.includes(gr)) {
|
if (auth?.groups.includes(gr)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
import Express from "express";
|
import Express from "express";
|
||||||
import { string } from "zod";
|
import { string } from "zod";
|
||||||
import {
|
import { addEvent, deleteEvent, getAllEvents, getEvent, updateEvent } from "../Controllers/event.controller";
|
||||||
addEvent,
|
|
||||||
deleteEvent,
|
|
||||||
getAllEvents,
|
|
||||||
getEvent,
|
|
||||||
updateEvent,
|
|
||||||
} from "../Controllers/event.controller";
|
|
||||||
import { requireAuthentication } from "../Middleware/auth/auth";
|
import { requireAuthentication } from "../Middleware/auth/auth";
|
||||||
const router = Express.Router();
|
const router = Express.Router();
|
||||||
|
|
||||||
|
|||||||
+25
-18
@@ -1,7 +1,14 @@
|
|||||||
import express from "express";
|
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, linkMedia, unlinkMedia, uploadImage } from "../Controllers/media.controller";
|
import {
|
||||||
|
deleteMedia,
|
||||||
|
getAllMedia,
|
||||||
|
getMediaMeta,
|
||||||
|
linkMedia,
|
||||||
|
unlinkMedia,
|
||||||
|
uploadImage,
|
||||||
|
} from "../Controllers/media.controller";
|
||||||
import eventRouter from "./event.routes";
|
import eventRouter from "./event.routes";
|
||||||
import disciplineRouter from "./discipline.routes";
|
import disciplineRouter from "./discipline.routes";
|
||||||
import roleSchemaRouter from "./role_schema.routes";
|
import roleSchemaRouter from "./role_schema.routes";
|
||||||
@@ -19,28 +26,28 @@ router.get("/:pid/meta", getMediaMeta);
|
|||||||
|
|
||||||
router.delete("/:pid", requireAuthentication, deleteMedia);
|
router.delete("/:pid", requireAuthentication, deleteMedia);
|
||||||
|
|
||||||
eventRouter.post<"/:pid/media", { pid: string }>(
|
eventRouter.post<"/:pid/media", { pid: string }>("/:pid/media", requireAuthentication, linkMedia);
|
||||||
"/:pid/media", requireAuthentication, linkMedia
|
|
||||||
|
eventRouter.delete<"/:pid/media/:mediaPid", { pid: string; mediaPid: string }>(
|
||||||
|
"/:pid/media/:mediaPid",
|
||||||
|
requireAuthentication,
|
||||||
|
unlinkMedia
|
||||||
);
|
);
|
||||||
|
|
||||||
eventRouter.delete<"/:pid/media/:mediaPid", { pid: string, mediaPid: string }>(
|
disciplineRouter.post<"/:pid/media", { pid: string }>("/:pid/media", requireAuthentication, linkMedia);
|
||||||
"/:pid/media/:mediaPid", requireAuthentication, unlinkMedia
|
|
||||||
|
disciplineRouter.delete<"/:pid/media/:mediaPid", { pid: string; mediaPid: string }>(
|
||||||
|
"/:pid/media/:mediaPid",
|
||||||
|
requireAuthentication,
|
||||||
|
unlinkMedia
|
||||||
);
|
);
|
||||||
|
|
||||||
disciplineRouter.post<"/:pid/media", { pid: string }>(
|
roleSchemaRouter.post<"/:pid/media", { pid: string }>("/:pid/media", requireAuthentication, linkMedia);
|
||||||
"/:pid/media", requireAuthentication, linkMedia
|
|
||||||
);
|
|
||||||
|
|
||||||
disciplineRouter.delete<"/:pid/media/:mediaPid", { pid: string, mediaPid: string }>(
|
roleSchemaRouter.delete<"/:pid/media/:mediaPid", { pid: string; mediaPid: string }>(
|
||||||
"/:pid/media/:mediaPid", requireAuthentication, unlinkMedia
|
"/:pid/media/:mediaPid",
|
||||||
);
|
requireAuthentication,
|
||||||
|
unlinkMedia
|
||||||
roleSchemaRouter.post<"/:pid/media", { pid: string }>(
|
|
||||||
"/:pid/media", requireAuthentication, linkMedia
|
|
||||||
);
|
|
||||||
|
|
||||||
roleSchemaRouter.delete<"/:pid/media/:mediaPid", { pid: string, mediaPid: string }>(
|
|
||||||
"/:pid/media/:mediaPid", requireAuthentication, unlinkMedia
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
Reference in New Issue
Block a user