Files
calendar/packages/trpc/server/routers/viewer/attributes/delete.handler.ts
T
08e1b0a9c8 feat: attributes (#15964)
Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com>
Co-authored-by: Omar López <zomars@me.com>
2024-08-15 14:49:05 -07:00

36 lines
771 B
TypeScript

import prisma from "@calcom/prisma";
import { TRPCError } from "@trpc/server";
import type { TrpcSessionUser } from "../../../trpc";
import type { ZDeleteAttributeSchema } from "./delete.schema";
type DeleteOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: ZDeleteAttributeSchema;
};
const deleteAttributeHandler = async ({ input, ctx }: DeleteOptions) => {
const org = ctx.user.organization;
if (!org.id) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You need to be apart of an organization to use this feature",
});
}
const attribute = await prisma.attribute.delete({
where: {
teamId: org.id,
id: input.id,
},
});
return attribute;
};
export default deleteAttributeHandler;