2023-05-09 19:27:05 +00:00
|
|
|
import type { PrismaClient } from "@prisma/client";
|
|
|
|
|
2023-06-15 08:58:07 +00:00
|
|
|
import { entityPrismaWhereClause } from "@calcom/lib/entityPermissionUtils";
|
2023-05-09 19:27:05 +00:00
|
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
|
|
|
|
import { getSerializableForm } from "../lib/getSerializableForm";
|
|
|
|
import type { TFormQueryInputSchema } from "./formQuery.schema";
|
|
|
|
|
|
|
|
interface FormsHandlerOptions {
|
|
|
|
ctx: {
|
|
|
|
prisma: PrismaClient;
|
|
|
|
user: NonNullable<TrpcSessionUser>;
|
|
|
|
};
|
|
|
|
input: TFormQueryInputSchema;
|
|
|
|
}
|
2023-06-15 08:58:07 +00:00
|
|
|
|
2023-05-09 19:27:05 +00:00
|
|
|
export const formQueryHandler = async ({ ctx, input }: FormsHandlerOptions) => {
|
|
|
|
const { prisma, user } = ctx;
|
|
|
|
const form = await prisma.app_RoutingForms_Form.findFirst({
|
|
|
|
where: {
|
2023-06-15 08:58:07 +00:00
|
|
|
AND: [
|
|
|
|
entityPrismaWhereClause({ userId: user.id }),
|
|
|
|
{
|
|
|
|
id: input.id,
|
|
|
|
},
|
|
|
|
],
|
2023-05-09 19:27:05 +00:00
|
|
|
},
|
|
|
|
include: {
|
2023-06-15 08:58:07 +00:00
|
|
|
team: { select: { slug: true, name: true } },
|
2023-05-09 19:27:05 +00:00
|
|
|
_count: {
|
|
|
|
select: {
|
|
|
|
responses: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!form) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-06-15 08:58:07 +00:00
|
|
|
return await getSerializableForm({ form });
|
2023-05-09 19:27:05 +00:00
|
|
|
};
|
2023-05-12 12:01:05 +00:00
|
|
|
|
|
|
|
export default formQueryHandler;
|