fix: address issues raised in preview PR

This commit is contained in:
Agusti Fernandez Pardo committed 2022-06-24 00:26:40 +02:00
1 parent 9b142640d5
commit 61c82eb197
11 files changed
+16 -15

No files matched your search

+1 -1
View File
@@ -1 +1 @@
export const PRISMA_CLIENT_CACHING_TIME = 1000 * 60 * 60 * 24;
export const PRISMA_CLIENT_CACHING_TIME = 1000 * 60 * 60 * 24; // = 86_400_000 ms, 24 hours / 1 day.
+1 -1
View File
@@ -3,7 +3,6 @@ import cache from "memory-cache";
import { NextMiddleware } from "next-api-middleware";
import { PRISMA_CLIENT_CACHING_TIME } from "@calcom/api/lib/constants";
// import prismaAdmin from "@calcom/console/modules/common/utils/prisma";
import { CONSOLE_URL } from "@calcom/lib/constants";
import { prisma, customPrisma } from "@calcom/prisma";
@@ -16,6 +15,7 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => {
if (!key) {
req.prisma = prisma;
await next();
return;
} else {
// If we have a key, we check if the deployment matching the key, has a databaseUrl value set.
const databaseUrl = await fetch(
+1 -1
View File
@@ -37,7 +37,7 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => {
// save the user id in the request for later use
req.userId = apiKey.userId;
// save the isAdmin boolean here for later use
req.isAdmin = await isAdminGuard(req.userId, prisma);
req.isAdmin = await isAdminGuard(req);
await next();
};
+3 -2
View File
@@ -1,6 +1,7 @@
import { PrismaClient, UserPermissionRole } from "@prisma/client";
import { UserPermissionRole } from "@prisma/client";
export const isAdminGuard = async (userId: number, prisma: PrismaClient) => {
export const isAdminGuard = async (req: NextApiRequest) => {
const { userId, prisma } = req;
const user = await prisma.user.findUnique({ where: { id: userId } });
return user?.role === UserPermissionRole.ADMIN;
};
+1 -1
View File
@@ -5,7 +5,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, prisma: PrismaClient) => {
const { userId, eventTypeId } = options;
const allWebhooks = await prisma.webhook.findMany({