mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
patching complications after merging and review suggestions
This commit is contained in:
@@ -3,6 +3,8 @@ import prisma from "../lib/prisma";
|
||||
import { createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common";
|
||||
import { requireLeaderOfTeam } from "../Middleware/auth/teamleaderAuth";
|
||||
import { z } from "zod";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import NotFoundError from "../Middleware/error/NotFoundError";
|
||||
|
||||
const TeamBody = z.object({
|
||||
teamName: z.string().min(1),
|
||||
@@ -69,18 +71,26 @@ export const updateTeam = async (req: Request, res: Response) => {
|
||||
return res.status(401).json(createInsufficientPermissionsError("STANDARD"));
|
||||
}
|
||||
|
||||
const team = prisma.team.update({
|
||||
where: {
|
||||
pid: body.pid,
|
||||
},
|
||||
data: {
|
||||
name: body.teamName,
|
||||
discipline: { connect: { pid: body.disciplineId } },
|
||||
leaderEmail: body.leaderEmail,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const team = prisma.team.update({
|
||||
where: {
|
||||
pid: body.pid,
|
||||
},
|
||||
data: {
|
||||
name: body.teamName,
|
||||
discipline: { connect: { pid: body.disciplineId } },
|
||||
leaderEmail: body.leaderEmail,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(204).json(team);
|
||||
res.status(204).json(team);
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
|
||||
throw new NotFoundError("discipline", body.pid);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteTeam = async (req: Request, res: Response) => {
|
||||
|
||||
Reference in New Issue
Block a user