mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
small fixes
This commit is contained in:
@@ -27,7 +27,7 @@ export const getAllAdmins = async (req: Request, res: Response) => {
|
||||
}
|
||||
|
||||
// TODO: Add exception handling
|
||||
const users = await prisma.admin.findMany({ select: { pid: true, name: true, permission_level: true } });
|
||||
const users = await prisma.admin.findMany({ select: { pid: true, name: true, permission_level: true, groups: { select: { pid: true } } } });
|
||||
|
||||
res.status(200).json({
|
||||
type: "success",
|
||||
|
||||
@@ -25,10 +25,19 @@ const updateGroupBody = z
|
||||
const basicGroup = {
|
||||
pid: true,
|
||||
name: true,
|
||||
level: true,
|
||||
organisation: { select: { pid: true, name: true } },
|
||||
} as const;
|
||||
|
||||
const detailedGroup = {
|
||||
pid: true,
|
||||
name: true,
|
||||
level: true,
|
||||
user_limit: true,
|
||||
organisation: { select: { pid: true, name: true } },
|
||||
participants: { select: { pid: true, firstName: true, lastName: true } },
|
||||
admins: { select: { pid: true, name: true } },
|
||||
}
|
||||
|
||||
export const _getAllGroups = async (res: Response, organisationId: string | undefined) => {
|
||||
const groups = await prisma.group.findMany({
|
||||
where: { organisation: { pid: organisationId } },
|
||||
@@ -77,12 +86,12 @@ export const getGroup = async (req: Request<GetGroupQueryParams>, res: Response)
|
||||
where: { pid },
|
||||
select: req.auth?.isAuthenticated
|
||||
? {
|
||||
pid: true,
|
||||
name: true,
|
||||
organisation: { select: { pid: true, name: true } },
|
||||
admins: { select: { pid: true, name: true } },
|
||||
participants: { select: { pid: true } },
|
||||
}
|
||||
pid: true,
|
||||
name: true,
|
||||
organisation: { select: { pid: true, name: true } },
|
||||
admins: { select: { pid: true, name: true } },
|
||||
participants: { select: { pid: true } },
|
||||
}
|
||||
: basicGroup,
|
||||
});
|
||||
|
||||
@@ -101,15 +110,15 @@ export const getGroup = async (req: Request<GetGroupQueryParams>, res: Response)
|
||||
},
|
||||
...(req.auth?.isAuthenticated
|
||||
? {
|
||||
admins: group.admins?.map((admin) => ({
|
||||
...admin,
|
||||
_links: [{ rel: "self", type: "GET", href: `/api/admins/${admin.pid}` }],
|
||||
})),
|
||||
participants: group.participants?.map((participant) => ({
|
||||
...participant,
|
||||
_links: [{ rel: "self", type: "GET", href: `/api/participant/${participant.pid}` }],
|
||||
})),
|
||||
}
|
||||
admins: group.admins?.map((admin) => ({
|
||||
...admin,
|
||||
_links: [{ rel: "self", type: "GET", href: `/api/admins/${admin.pid}` }],
|
||||
})),
|
||||
participants: group.participants?.map((participant) => ({
|
||||
...participant,
|
||||
_links: [{ rel: "self", type: "GET", href: `/api/participant/${participant.pid}` }],
|
||||
})),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
@@ -164,7 +173,7 @@ export const updateGroup = async (req: Request<{ pid: string }>, res: Response)
|
||||
user_limit: body.user_limit,
|
||||
level: body.level,
|
||||
},
|
||||
select: basicGroup,
|
||||
select: detailedGroup,
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
|
||||
@@ -85,9 +85,10 @@ export const updateTeam = async (req: Request, res: Response) => {
|
||||
discipline: { connect: { pid: body.disciplineId } },
|
||||
leaderEmail: body.leaderEmail,
|
||||
},
|
||||
select: basicTeam,
|
||||
});
|
||||
|
||||
res.status(204).json({ type: "success", payload: { team } });
|
||||
res.status(200).json({ type: "success", payload: { team } });
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
|
||||
throw new NotFoundError("team", pid);
|
||||
|
||||
Reference in New Issue
Block a user