patching complications after merging and review suggestions

This commit is contained in:
Laurin
2022-06-02 00:09:51 +02:00
parent 95784a2a9f
commit 569695245f
10 changed files with 185 additions and 309 deletions
+24 -63
View File
@@ -8,6 +8,30 @@ import { createInsufficientPermissionsError, DataType, generateInvalidBodyError
require("express-async-errors");
const detailedRole = {
pid: true,
score: true,
schema: {
select: {
pid: true,
name: true,
},
},
participant: {
select: {
pid: true,
firstName: true,
lastName: true,
},
},
team: {
select: {
pid: true,
name: true,
},
},
};
/**
*
* @param teamPid: Pid of the team to add the roles to
@@ -94,66 +118,3 @@ export async function assignParticipantToRole(req: Request<{ pid: string }>, res
},
});
}
export const updateRoleScore = async (req: Request<{ pid: string }, {}, { score: string }>, res: Response) => {
if (req.auth?.permission_level != "ELEVATED") {
res.status(403).json(createInsufficientPermissionsError());
}
const { score } = req.body;
if (typeof score !== "string") {
res.status(400).json(generateInvalidBodyError({ score: DataType.STRING }));
}
const { pid } = req.params;
try {
const role = await prisma.role.update({
where: { pid },
data: { score },
select: {
pid: true,
score: true,
schema: {
select: {
pid: true,
name: true,
},
},
participant: {
select: {
pid: true,
firstName: true,
lastName: true,
},
},
team: {
select: {
pid: true,
name: true,
},
},
},
});
res.status(200).json({
type: "success",
payload: {
role,
},
});
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
throw new NotFoundError("role", pid);
}
throw e;
}
};
export async function deleteRolesFromTeam(teamPid: string) {
await prisma.role.deleteMany({
where: { team: { pid: teamPid } },
});
}