add validation for teams in the event type creation (#1866)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Edward Fernándezandkodiakhq[bot] authored and GitHub committed 2022-02-15 14:51:01 -07:00
1 parent 7c6e394416
commit 14a9fdf78c
3 files changed
+27 -1

No files matched your search

+17 -1
View File
@@ -108,16 +108,32 @@ export const eventTypesRouter = createProtectedRouter()
input: createEventTypeInput,
async resolve({ ctx, input }) {
const { schedulingType, teamId, ...rest } = input;
const userId = ctx.user.id;
const data: Prisma.EventTypeCreateInput = {
...rest,
users: {
connect: {
id: ctx.user.id,
id: userId,
},
},
};
if (teamId && schedulingType) {
const hasMembership = await ctx.prisma.membership.findFirst({
where: {
userId,
teamId: teamId,
accepted: true,
},
});
if (!hasMembership) {
console.warn(`User ${userId} does not have permission to create this new event type`);
throw new TRPCError({ code: "UNAUTHORIZED" });
}
data.team = {
connect: {
id: teamId,