Files
calendar/packages/app-store/routing-forms/lib/isFormCreateEditAllowed.ts
T
Udit TakkarandGitHub 4e0e3a47f5 perf: routing forms loading time (#17518)
* perf: routing forms loading time

* chore: add TODO

* chore

* chore: add type

* chore: use Promise.all

* fix: type err

* fix: fetch id

* refactor: don't fetch team

* chore: add name
2024-11-12 17:32:42 +05:30

37 lines
780 B
TypeScript

import type { App_RoutingForms_Form, User } from "@prisma/client";
import { canCreateEntity, canEditEntity } from "@calcom/lib/entityPermissionUtils";
import prisma from "@calcom/prisma";
export async function isFormCreateEditAllowed({
formId,
userId,
/**
* Valid when a new form is being created for a team
*/
targetTeamId,
}: {
userId: User["id"];
formId: App_RoutingForms_Form["id"];
targetTeamId: App_RoutingForms_Form["teamId"] | null;
}) {
const form = await prisma.app_RoutingForms_Form.findUnique({
where: {
id: formId,
},
select: {
userId: true,
teamId: true,
},
});
if (!form) {
return await canCreateEntity({
targetTeamId,
userId,
});
}
return await canEditEntity(form, userId);
}