mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
small fixes
This commit is contained in:
@@ -18,13 +18,14 @@ import { requireConfiguredAuthentication, requireResponsibleForGroup } from "../
|
||||
// REVIEW: All this code should be able to be executed by the teamleader of the team the participant is in AND
|
||||
// an admin the group of whom overlaps with the team AND an elevated admin
|
||||
|
||||
const ParticipantBody = z.object({
|
||||
const InitialParticipant = z.object({
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
groupId: z.string().uuid(),
|
||||
//job: z.enum(["TEAMLEADER", "MEMBER"]),
|
||||
groupPid: z.string().uuid(),
|
||||
});
|
||||
|
||||
const ParticipantBody = InitialParticipant.extend({ teamPid: z.string().uuid() });
|
||||
|
||||
const returnedParticipant = {
|
||||
pid: true,
|
||||
firstName: true,
|
||||
@@ -45,7 +46,7 @@ const returnedParticipant = {
|
||||
} as const;
|
||||
|
||||
// at: POST api/teams/:teamPid/participant/
|
||||
export const createParticipant = async (req: Request<{ teamPid: string }>, res: Response) => {
|
||||
export const createParticipant = async (req: Request, res: Response) => {
|
||||
const result = ParticipantBody.safeParse(req.body);
|
||||
|
||||
if (result.success === false) {
|
||||
@@ -54,14 +55,14 @@ export const createParticipant = async (req: Request<{ teamPid: string }>, res:
|
||||
{
|
||||
firstname: DataType.STRING,
|
||||
lastName: DataType.STRING,
|
||||
groupId: DataType.UUID,
|
||||
groupPid: DataType.UUID,
|
||||
teamPid: DataType.UUID,
|
||||
},
|
||||
result.error
|
||||
)
|
||||
);
|
||||
}
|
||||
const body = result.data;
|
||||
const { teamPid } = req.params;
|
||||
|
||||
try {
|
||||
const participant = await prisma.participant.create({
|
||||
@@ -69,8 +70,8 @@ export const createParticipant = async (req: Request<{ teamPid: string }>, res:
|
||||
firstName: body.firstName,
|
||||
lastName: body.lastName,
|
||||
relevance: "MEMBER",
|
||||
group: { connect: { pid: body.groupId } },
|
||||
team: { connect: { pid: teamPid } },
|
||||
group: { connect: { pid: body.groupPid } },
|
||||
team: { connect: { pid: body.teamPid } },
|
||||
},
|
||||
select: returnedParticipant,
|
||||
});
|
||||
@@ -83,7 +84,7 @@ export const createParticipant = async (req: Request<{ teamPid: string }>, res:
|
||||
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
|
||||
return res
|
||||
.status(404)
|
||||
.json(generateError(`Could not link to team with ID '${teamPid}, or group with ID ${body.groupId}'`));
|
||||
.json(generateError(`Could not link to team with ID '${body.teamPid}, or group with ID ${body.groupPid}'`));
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
@@ -91,7 +92,7 @@ export const createParticipant = async (req: Request<{ teamPid: string }>, res:
|
||||
|
||||
// at: PATCH api/participants/:pid/
|
||||
export const updateParticipant = async (req: Request<{ pid: string }>, res: Response) => {
|
||||
const result = ParticipantBody.partial().safeParse(req.body);
|
||||
const result = InitialParticipant.partial().safeParse(req.body);
|
||||
|
||||
if (result.success === false) {
|
||||
return res.status(400).json(
|
||||
@@ -99,7 +100,7 @@ export const updateParticipant = async (req: Request<{ pid: string }>, res: Resp
|
||||
{
|
||||
firstname: DataType.STRING,
|
||||
lastName: DataType.STRING,
|
||||
groupId: DataType.UUID,
|
||||
groupPid: DataType.UUID,
|
||||
},
|
||||
result.error
|
||||
)
|
||||
@@ -115,7 +116,7 @@ export const updateParticipant = async (req: Request<{ pid: string }>, res: Resp
|
||||
data: {
|
||||
firstName: body.firstName,
|
||||
lastName: body.lastName,
|
||||
group: { connect: { pid: body.groupId } },
|
||||
group: { connect: { pid: body.groupPid } },
|
||||
},
|
||||
select: returnedParticipant,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user