Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com> Co-authored-by: Omar López <zomars@me.com>
36 lines
771 B
TypeScript
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;
|