mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
fixed in pr requested changes
This commit is contained in:
+146
-146
@@ -1,146 +1,146 @@
|
||||
// Schema for the main database
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
model Event {
|
||||
id Int @id @default(autoincrement()) // Primary key
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid // Public key
|
||||
date DateTime
|
||||
name String
|
||||
briefDescription String
|
||||
fullDescription String?
|
||||
|
||||
disciplines Discipline[]
|
||||
organisations Organisation[]
|
||||
visual Media[]
|
||||
}
|
||||
|
||||
model Admin {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String @unique
|
||||
password String // TODO: Probably specify hash size (VarChar or some other type)
|
||||
|
||||
permission_level AdminLevel @default(STANDARD)
|
||||
revision DateTime @default(now())
|
||||
groups Group[]
|
||||
}
|
||||
|
||||
model Discipline {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
briefDescription String @default("description")
|
||||
fullDescription String?
|
||||
minTeamSize Int
|
||||
maxTeamSize Int
|
||||
|
||||
roles RoleSchema[]
|
||||
teams Team[]
|
||||
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
|
||||
eventId Int
|
||||
visual Media[]
|
||||
}
|
||||
|
||||
model RoleSchema {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
schema Json
|
||||
|
||||
roles Role[]
|
||||
discipline Discipline @relation(fields: [disciplineId], references: [id], onDelete: Cascade)
|
||||
disciplineId Int
|
||||
visual Media[]
|
||||
}
|
||||
|
||||
model Team {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
leaderEmail String
|
||||
verified Boolean @default(false)
|
||||
creationDate DateTime @default(now())
|
||||
|
||||
roles Role[] @relation(name: "participants")
|
||||
participants Participant[]
|
||||
discipline Discipline @relation(fields: [disciplineId], references: [id], onDelete: Cascade)
|
||||
disciplineId Int
|
||||
}
|
||||
|
||||
model Participant {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
firstName String
|
||||
lastName String
|
||||
relevance Job
|
||||
|
||||
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
|
||||
groupId Int
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
teamId Int
|
||||
roles Role[]
|
||||
}
|
||||
|
||||
model Role {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()"))
|
||||
score String
|
||||
|
||||
participant Participant? @relation(fields: [participantId], references: [id], onDelete: SetNull)
|
||||
participantId Int?
|
||||
team Team @relation(name: "participants", fields: [teamId], references: [id], onDelete: Cascade)
|
||||
teamId Int
|
||||
schema RoleSchema @relation(fields: [schemaId], references: [id], onDelete: Cascade)
|
||||
schemaId Int
|
||||
}
|
||||
|
||||
model Organisation {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
|
||||
groups Group[]
|
||||
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
|
||||
eventId Int
|
||||
}
|
||||
|
||||
model Group {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
user_limit Int @default(40)
|
||||
level Int
|
||||
|
||||
organisation Organisation @relation(fields: [organisationId], references: [id], onDelete: Cascade)
|
||||
organisationId Int
|
||||
participants Participant[]
|
||||
admins Admin[]
|
||||
}
|
||||
|
||||
model Media {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique
|
||||
description String @default("visual")
|
||||
|
||||
events Event[]
|
||||
disciplines Discipline[]
|
||||
roles RoleSchema[]
|
||||
}
|
||||
|
||||
enum AdminLevel {
|
||||
STANDARD
|
||||
ELEVATED
|
||||
}
|
||||
|
||||
enum Job {
|
||||
TEAMLEADER
|
||||
MEMBER
|
||||
}
|
||||
// Schema for the main database
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
model Event {
|
||||
id Int @id @default(autoincrement()) // Primary key
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid // Public key
|
||||
date DateTime
|
||||
name String
|
||||
briefDescription String
|
||||
fullDescription String?
|
||||
|
||||
disciplines Discipline[]
|
||||
organisations Organisation[]
|
||||
visual Media[]
|
||||
}
|
||||
|
||||
model Admin {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String @unique
|
||||
password String // TODO: Probably specify hash size (VarChar or some other type)
|
||||
|
||||
permission_level AdminLevel @default(STANDARD)
|
||||
revision DateTime @default(now())
|
||||
groups Group[]
|
||||
}
|
||||
|
||||
model Discipline {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
briefDescription String @default("description")
|
||||
fullDescription String?
|
||||
minTeamSize Int
|
||||
maxTeamSize Int
|
||||
|
||||
roles RoleSchema[]
|
||||
teams Team[]
|
||||
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
|
||||
eventId Int
|
||||
visual Media[]
|
||||
}
|
||||
|
||||
model RoleSchema {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
schema Json
|
||||
|
||||
roles Role[]
|
||||
discipline Discipline @relation(fields: [disciplineId], references: [id], onDelete: Cascade)
|
||||
disciplineId Int
|
||||
visual Media[]
|
||||
}
|
||||
|
||||
model Team {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
leaderEmail String
|
||||
verified Boolean @default(false)
|
||||
creationDate DateTime @default(now())
|
||||
|
||||
roles Role[] @relation(name: "participants")
|
||||
participants Participant[]
|
||||
discipline Discipline @relation(fields: [disciplineId], references: [id], onDelete: Cascade)
|
||||
disciplineId Int
|
||||
}
|
||||
|
||||
model Participant {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
firstName String
|
||||
lastName String
|
||||
relevance Job
|
||||
|
||||
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
|
||||
groupId Int
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
teamId Int
|
||||
roles Role[]
|
||||
}
|
||||
|
||||
model Role {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()"))
|
||||
score String
|
||||
|
||||
participant Participant? @relation(fields: [participantId], references: [id], onDelete: SetNull)
|
||||
participantId Int?
|
||||
team Team @relation(name: "participants", fields: [teamId], references: [id], onDelete: Cascade)
|
||||
teamId Int
|
||||
schema RoleSchema @relation(fields: [schemaId], references: [id], onDelete: Cascade)
|
||||
schemaId Int
|
||||
}
|
||||
|
||||
model Organisation {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
|
||||
groups Group[]
|
||||
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
|
||||
eventId Int
|
||||
}
|
||||
|
||||
model Group {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
user_limit Int @default(40)
|
||||
level Int
|
||||
|
||||
organisation Organisation @relation(fields: [organisationId], references: [id], onDelete: Cascade)
|
||||
organisationId Int
|
||||
participants Participant[]
|
||||
admins Admin[]
|
||||
}
|
||||
|
||||
model Media {
|
||||
id Int @id @default(autoincrement())
|
||||
pid String @unique
|
||||
description String @default("visual")
|
||||
|
||||
events Event[]
|
||||
disciplines Discipline[]
|
||||
roles RoleSchema[]
|
||||
}
|
||||
|
||||
enum AdminLevel {
|
||||
STANDARD
|
||||
ELEVATED
|
||||
}
|
||||
|
||||
enum Job {
|
||||
TEAMLEADER
|
||||
MEMBER
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { requireResponsibleForGroups } from "../Middleware/auth/auth";
|
||||
import AuthError from "../Middleware/error/AuthError";
|
||||
import { runInNewContext } from "vm";
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
|
||||
import logger from "../Middleware/error/logger";
|
||||
|
||||
require("express-async-errors");
|
||||
|
||||
@@ -53,7 +54,7 @@ export const getTeams = async (req: Request, res: Response) => {
|
||||
}
|
||||
const teams = await prisma.team.findMany({ where: verified, select: basicTeam });
|
||||
|
||||
res.status(200).json({ type: "success", payload: { teams } });
|
||||
return res.status(200).json({ type: "success", payload: { teams } });
|
||||
};
|
||||
|
||||
export const getTeam = async (req: Request<{ pid: string }>, res: Response) => {
|
||||
@@ -66,7 +67,7 @@ export const getTeam = async (req: Request<{ pid: string }>, res: Response) => {
|
||||
}
|
||||
|
||||
const team = await prisma.team.findUnique({
|
||||
where: { pid: pid },
|
||||
where: { pid },
|
||||
select: detailedTeam,
|
||||
});
|
||||
|
||||
@@ -140,7 +141,7 @@ export const deleteTeam = async (req: Request, res: Response) => {
|
||||
try {
|
||||
await prisma.team.delete({ where: { pid } });
|
||||
|
||||
res.status(204).json({ type: "success", payload: { message: "Sucesfully deleted team" } });
|
||||
res.status(204).json({ type: "success", payload: { message: "Succesfully deleted team" } });
|
||||
} catch (e) {
|
||||
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
|
||||
throw new NotFoundError("team", pid);
|
||||
@@ -151,11 +152,15 @@ export const deleteTeam = async (req: Request, res: Response) => {
|
||||
};
|
||||
|
||||
export const deleteUnverifiedTeams = async (req: Request, res: Response) => {
|
||||
if (req.auth?.permission_level == "STANDARD") {
|
||||
throw new AuthError("A STANDARD Admin is not allowed to delete unverified teams!");
|
||||
}
|
||||
|
||||
const { pid } = req.params;
|
||||
|
||||
await _deleteUnverifiedTeams(pid);
|
||||
|
||||
res.status(204).end();
|
||||
res.status(204).send();
|
||||
};
|
||||
|
||||
export async function checkTeamExistence(teamPid: string) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import express from "express";
|
||||
import { requireConfiguredAuthentication } from "../Middleware/auth/auth";
|
||||
import { deleteTeam, deleteUnverifiedTeams, getTeam, getTeams, updateTeam } from "../Controllers/team.controller";
|
||||
import { deleteTeam, getTeam, getTeams, updateTeam } from "../Controllers/team.controller";
|
||||
import { getRolesForTeam } from "../Controllers/role.controller";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
Reference in New Issue
Block a user