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