fix: move patch to no then/catch
parent
3f6e7904cb
commit
f985bbd1ff
|
@ -39,7 +39,7 @@ export async function patchHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
});
|
});
|
||||||
const userTeamIds = userWithMemberships.map((membership) => membership.teamId);
|
const userTeamIds = userWithMemberships.map((membership) => membership.teamId);
|
||||||
// Here we only check for ownership of the user if the user is not admin, otherwise we let ADMIN's edit any user
|
// Here we only check for ownership of the user if the user is not admin, otherwise we let ADMIN's edit any user
|
||||||
if (!isAdmin && !userTeamIds.includes(query.teamId))
|
if (!isAdmin || !userTeamIds.includes(query.teamId))
|
||||||
throw new HttpError({ statusCode: 401, message: "Unauthorized" });
|
throw new HttpError({ statusCode: 401, message: "Unauthorized" });
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
{
|
{
|
||||||
|
@ -47,16 +47,11 @@ export async function patchHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await prisma.team
|
const data = await prisma.team.update({ where: { id: query.teamId }, data: safeBody.data });
|
||||||
.update({ where: { id: query.teamId }, data: safeBody.data })
|
if (!data) throw new HttpError({ statusCode: 404, message: `Team with id: ${query.teamId} not found` });
|
||||||
.then((team) => schemaTeamReadPublic.parse(team))
|
const team = schemaTeamReadPublic.parse(data);
|
||||||
.then((team) => res.status(200).json({ team }))
|
if (!team) throw new HttpError({ statusCode: 401, message: `Your request body wasn't valid` });
|
||||||
.catch((error: Error) =>
|
return { team };
|
||||||
res.status(404).json({
|
|
||||||
message: `Team with id: ${query.teamId} not found`,
|
|
||||||
error,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defaultResponder(patchHandler);
|
export default defaultResponder(patchHandler);
|
||||||
|
|
Loading…
Reference in New Issue