Adds team event type check

This commit is contained in:
Syed Ali Shahbaz authored and GitHub committed 2022-06-08 13:06:28 +05:30
1 parent 1180f3f258
commit cd03f5a821
1 file changed
+21
+21
View File
@@ -95,6 +95,27 @@ export async function WebhookById(
return;
}
}
if (safeBody.data.eventTypeId) {
const team = await ctx.prisma.team.findFirst({
where: {
eventTypes: {
some: {
id: safeBody.data.eventTypeId,
},
},
},
include: {
members: true,
},
});
// Team should be available and the user should be a member of the team
if (!team?.members.some((membership) => membership.userId === userId)) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
}
}
await prisma.webhook
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
.then((data) => schemaWebhookReadPublic.parse(data))