cal.pub0.org/packages/trpc/server/routers/viewer/apiKeys/edit.handler.ts

43 lines
733 B
TypeScript
Raw Normal View History

import prisma from "@calcom/prisma";
import type { TrpcSessionUser } from "../../../trpc";
import type { TEditInputSchema } from "./edit.schema";
type EditOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TEditInputSchema;
};
export const editHandler = async ({ ctx, input }: EditOptions) => {
const { id, ...data } = input;
const {
apiKeys: [updatedApiKey],
} = await prisma.user.update({
where: {
id: ctx.user.id,
},
data: {
apiKeys: {
update: {
where: {
id,
},
data,
},
},
},
select: {
apiKeys: {
where: {
id,
},
},
},
});
return updatedApiKey;
};