* 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
37 lines
780 B
TypeScript
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);
|
|
}
|