fix: make isAdmin require req.prisma too

This commit is contained in:
Agusti Fernandez Pardo committed 2022-06-18 03:03:13 +02:00
1 parent cc534a2914
commit 60688e2e91
8 files changed
+10 -12

No files matched your search

+1 -1
View File
@@ -34,7 +34,7 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => {
/* We save the user id in the request for later use */
req.userId = apiKey.userId;
/* We save the isAdmin boolean here for later use */
req.isAdmin = await isAdminGuard(req.userId);
req.isAdmin = await isAdminGuard(req.userId, prisma);
await next();
};
+2 -4
View File
@@ -1,8 +1,6 @@
import { UserPermissionRole } from "@prisma/client";
import { PrismaClient, UserPermissionRole } from "@prisma/client";
import prisma from "@calcom/prisma";
export const isAdminGuard = async (userId: number) => {
export const isAdminGuard = async (userId: number, prisma: PrismaClient) => {
const user = await prisma.user.findUnique({ where: { id: userId } });
return user?.role === UserPermissionRole.ADMIN;
};
+1 -1
View File
@@ -7,7 +7,7 @@ export type GetSubscriberOptions = {
eventTypeId: number;
triggerEvent: WebhookTriggerEvents;
};
/** @note will this not work with custom prisma? since we're importing prisma directly and not passing it from request here **/
const getWebhooks = async (options: GetSubscriberOptions) => {
const { userId, eventTypeId } = options;
const allWebhooks = await prisma.webhook.findMany({