* trpc procedures an middleware refactor * allow use sessionMiddleware without a req object * sync with the new tRPC structure * tRPC refactor on routing form app * import Prisma from @prisma/client * Lazy load apps from appstore * remove unrelated changes * Add types for PaymentService * type fixes * Merge branch 'main' into roae85/cal-1514-set-the-user-session-only-on-the * fix typo * remove console.log * remove explicit types from apstore object * linter fixes --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import type { PrismaClient } from "@prisma/client";
|
|
|
|
import { TRPCError } from "@calcom/trpc/server";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import getConnectedForms from "../lib/getConnectedForms";
|
|
import { isFormEditAllowed } from "../lib/isFormEditAllowed";
|
|
import type { TDeleteFormInputSchema } from "./deleteForm.schema";
|
|
|
|
interface DeleteFormHandlerOptions {
|
|
ctx: {
|
|
prisma: PrismaClient;
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TDeleteFormInputSchema;
|
|
}
|
|
export const deleteFormHandler = async ({ ctx, input }: DeleteFormHandlerOptions) => {
|
|
const { user, prisma } = ctx;
|
|
if (!(await isFormEditAllowed({ userId: user.id, formId: input.id }))) {
|
|
throw new TRPCError({
|
|
code: "FORBIDDEN",
|
|
});
|
|
}
|
|
|
|
const areFormsUsingIt = (
|
|
await getConnectedForms(prisma, {
|
|
id: input.id,
|
|
userId: user.id,
|
|
})
|
|
).length;
|
|
if (areFormsUsingIt) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: "This form is being used by other forms. Please remove it's usage from there first.",
|
|
});
|
|
}
|
|
return await prisma.app_RoutingForms_Form.deleteMany({
|
|
where: {
|
|
id: input.id,
|
|
userId: user.id,
|
|
},
|
|
});
|
|
};
|