2
0
Files
2024-08-09 00:39:27 +02:00

67 lines
1.3 KiB
TypeScript

import { prisma } from "@calcom/prisma";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { TRPCError } from "@trpc/server";
import type { TGetInputSchema } from "./get.schema";
import { isAuthorized } from "./util";
type GetOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TGetInputSchema;
};
export const getHandler = async ({ ctx, input }: GetOptions) => {
const workflow = await prisma.workflow.findFirst({
where: {
id: input.id,
},
select: {
id: true,
name: true,
userId: true,
teamId: true,
isActiveOnAll: true,
team: {
select: {
id: true,
slug: true,
members: true,
name: true,
isOrganization: true,
},
},
time: true,
timeUnit: true,
activeOn: {
select: {
eventType: true,
},
},
activeOnTeams: {
select: {
team: true,
},
},
trigger: true,
steps: {
orderBy: {
stepNumber: "asc",
},
},
},
});
const isUserAuthorized = await isAuthorized(workflow, ctx.user.id);
if (!isUserAuthorized) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
}
return workflow;
};