-
Notifications
You must be signed in to change notification settings - Fork 8.9k
/
Copy pathdelete.handler.ts
48 lines (41 loc) · 984 Bytes
/
delete.handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import prisma from "@calcom/prisma";
import type { TrpcSessionUser } from "../../../trpc";
import type { TDeleteInputSchema } from "./delete.schema";
type DeleteOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TDeleteInputSchema;
};
export const deleteHandler = async ({ ctx, input }: DeleteOptions) => {
const { id } = input;
const apiKeyToDelete = await prisma.apiKey.findFirst({
where: {
id,
},
});
await prisma.user.update({
where: {
id: ctx.user.id,
},
data: {
apiKeys: {
delete: {
id,
},
},
},
});
//remove all existing zapier webhooks, as we always have only one zapier API key and the running zaps won't work any more if this key is deleted
if (apiKeyToDelete && apiKeyToDelete.appId === "zapier") {
await prisma.webhook.deleteMany({
where: {
userId: ctx.user.id,
appId: "zapier",
},
});
}
return {
id,
};
};