mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
patched issues found during testing
This commit is contained in:
@@ -20,7 +20,7 @@ const InitialDisciplineBody = z.object({
|
||||
name: z.string().min(1),
|
||||
minTeamSize: z.number(),
|
||||
maxTeamSize: z.number(),
|
||||
briefDescription: z.string(),
|
||||
briefDescription: z.string().min(1),
|
||||
fullDescription: z.string(),
|
||||
});
|
||||
|
||||
@@ -29,9 +29,7 @@ const disciplineRefiner = [
|
||||
{ message: "The minTeamSize must be smaller or equal to the maxTeamSize" },
|
||||
] as const;
|
||||
|
||||
const DisciplineBody = InitialDisciplineBody.partial({ briefDescription: true, fullDescription: true }).refine(
|
||||
...disciplineRefiner
|
||||
);
|
||||
const DisciplineBody = InitialDisciplineBody.partial({ fullDescription: true }).refine(...disciplineRefiner);
|
||||
const updateDisciplineBody = InitialDisciplineBody.partial().refine(...disciplineRefiner);
|
||||
|
||||
const basicDiscipline = {
|
||||
@@ -158,17 +156,19 @@ export const createDiscipline = async (req: Request<{ eventPid: string }, {}, Cr
|
||||
name: DataType.STRING,
|
||||
minTeamSize: DataType.NUMBER,
|
||||
maxTeamSize: DataType.NUMBER,
|
||||
briefDescription: DataType.STRING,
|
||||
["fullDescription?"]: DataType.STRING,
|
||||
},
|
||||
result.error
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const { name, minTeamSize, maxTeamSize } = result.data;
|
||||
const { name, minTeamSize, maxTeamSize, briefDescription } = result.data;
|
||||
|
||||
try {
|
||||
const discipline = await prisma.discipline.create({
|
||||
data: { name, minTeamSize, maxTeamSize, event: { connect: { pid: req.params.eventPid } } },
|
||||
data: { name, minTeamSize, maxTeamSize, briefDescription, event: { connect: { pid: req.params.eventPid } } },
|
||||
select: basicDiscipline,
|
||||
});
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ export const deleteGroup = async (req: Request<DeleteGroupQueryParams>, res: Res
|
||||
const { pid } = req.params;
|
||||
|
||||
try {
|
||||
prisma.group.delete({ where: { pid } });
|
||||
await prisma.group.delete({ where: { pid } });
|
||||
|
||||
return res.status(204).end();
|
||||
} catch (e) {
|
||||
|
||||
@@ -213,7 +213,7 @@ export const deleteOrganisation = async (req: Request<DeleteOrganisationQueryPar
|
||||
const { pid } = req.params;
|
||||
|
||||
try {
|
||||
prisma.organisation.delete({ where: { pid } });
|
||||
await prisma.organisation.delete({ where: { pid } });
|
||||
|
||||
res.status(204).end();
|
||||
} catch (e) {
|
||||
|
||||
@@ -91,8 +91,6 @@ export async function assignParticipantToRole(req: Request<{ pid: string }>, res
|
||||
const { participantPid } = zBody.data;
|
||||
const rolePid = req.params.pid;
|
||||
|
||||
requireResponsibleForParticipant(req.teamleader, participantPid);
|
||||
|
||||
const schema = await prisma.role.findFirst({
|
||||
where: { pid: rolePid, team: { participants: { some: { pid: participantPid } } } },
|
||||
select: { participant: { select: { pid: true, firstName: true, lastName: true } } },
|
||||
|
||||
@@ -24,8 +24,28 @@ interface CreateTeamBody {
|
||||
partGroupId: string;
|
||||
}
|
||||
|
||||
export const basicTeam = {
|
||||
pid: true,
|
||||
name: true,
|
||||
discipline: { select: { pid: true } },
|
||||
roles: {
|
||||
select: {
|
||||
pid: true,
|
||||
schema: { select: { name: true } },
|
||||
participant: { select: { pid: true } },
|
||||
},
|
||||
},
|
||||
participants: {
|
||||
select: {
|
||||
pid: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const getTeams = async (req: Request, res: Response) => {
|
||||
const teams = prisma.team.findMany({ select: { pid: true, name: true, disciplineId: true } });
|
||||
const teams = await prisma.team.findMany({ select: basicTeam });
|
||||
|
||||
res.status(200).json(teams);
|
||||
};
|
||||
@@ -33,13 +53,9 @@ export const getTeams = async (req: Request, res: Response) => {
|
||||
export const getTeam = async (req: Request, res: Response) => {
|
||||
const { pid } = req.params;
|
||||
|
||||
const team = prisma.team.findUnique({
|
||||
const team = await prisma.team.findUnique({
|
||||
where: { pid },
|
||||
select: {
|
||||
disciplineId: true,
|
||||
name: true,
|
||||
pid: true,
|
||||
},
|
||||
select: basicTeam,
|
||||
});
|
||||
|
||||
res.status(200).json(team);
|
||||
@@ -72,7 +88,7 @@ export const updateTeam = async (req: Request, res: Response) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const team = prisma.team.update({
|
||||
const team = await prisma.team.update({
|
||||
where: {
|
||||
pid: body.pid,
|
||||
},
|
||||
@@ -96,13 +112,7 @@ export const updateTeam = async (req: Request, res: Response) => {
|
||||
export const deleteTeam = async (req: Request, res: Response) => {
|
||||
const { pid } = req.params;
|
||||
|
||||
try {
|
||||
requireLeaderOfTeam(req.teamleader, pid);
|
||||
} catch {
|
||||
return res.status(401).json(createInsufficientPermissionsError("STANDARD"));
|
||||
}
|
||||
|
||||
prisma.team.delete({ where: { pid } });
|
||||
await prisma.team.delete({ where: { pid } });
|
||||
|
||||
res.status(204).json("Welp its gone");
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ import { createInsufficientPermissionsError, DataType, generateInvalidBodyError
|
||||
import { generateTeamleaderJWT, requireLeaderOfTeam } from "../Middleware/auth/teamleaderAuth";
|
||||
import { createRolesForTeam } from "./role.controller";
|
||||
import { any, z } from "zod";
|
||||
import { basicTeam } from "./team.controller";
|
||||
|
||||
const TeamBody = z.object({
|
||||
teamName: z.string().min(1),
|
||||
@@ -70,13 +71,13 @@ export const register = async (req: Request<{}, {}, CreateTeamBody>, res: Respon
|
||||
},
|
||||
});
|
||||
|
||||
//TODO: maybe use returned amount of created use?
|
||||
createRolesForTeam(team.pid);
|
||||
await createRolesForTeam(team.pid);
|
||||
|
||||
const usid = nanoid();
|
||||
|
||||
(await mailClient).set(usid, team.pid);
|
||||
|
||||
// TODO: fix "eventname"
|
||||
verificationMail(req.body.leaderEmail, "eventname", usid);
|
||||
|
||||
res.status(201).json({ type: "success", payload: { team } });
|
||||
@@ -103,6 +104,7 @@ export const requestToken = async (req: Request, res: Response) => {
|
||||
|
||||
(await mailClient).set(usid, team.pid);
|
||||
|
||||
// TODO: fix "eventname"
|
||||
verificationMail(team.leaderEmail, "eventname", usid);
|
||||
|
||||
res.status(200).json({ type: "sucess", message: "Email sent!" });
|
||||
|
||||
Reference in New Issue
Block a user