Added team event check to POST

pull/9078/head
Syed Ali Shahbaz 2022-06-08 13:12:05 +05:30 committed by GitHub
parent cd03f5a821
commit bae84f2ce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -61,6 +61,27 @@ async function createOrlistAllWebhooks(
res.status(400).json({ message: "Invalid request body" });
return;
}
if (safe.data.eventTypeId) {
const team = await ctx.prisma.team.findFirst({
where: {
eventTypes: {
some: {
id: safe.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",
});
}
}
const data = await prisma.webhook.create({ data: { id: uuidv4(), ...safe.data, userId } });
if (data) res.status(201).json({ webhook: data, message: "Webhook created successfully" });
else