Files
sign/packages/lib/server-only/webhooks/zapier/unsubscribe.ts

30 lines
766 B
TypeScript
Raw Normal View History

2024-02-24 11:18:58 +02:00
import type { NextApiRequest, NextApiResponse } from 'next';
import { prisma } from '@documenso/prisma';
import { validateApiToken } from './validateApiToken';
export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
const { authorization } = req.headers;
2024-02-27 12:13:56 +11:00
2024-02-24 11:18:58 +02:00
const { webhookId } = req.body;
2024-02-27 12:13:56 +11:00
2024-02-27 15:22:02 +02:00
const result = await validateApiToken({ authorization });
2024-02-24 11:18:58 +02:00
const deletedWebhook = await prisma.webhook.delete({
where: {
id: webhookId,
2024-02-28 08:10:38 +02:00
userId: result.userId ?? result.user.id,
teamId: result.teamId ?? undefined,
2024-02-24 11:18:58 +02:00
},
});
return res.status(200).json(deletedWebhook);
} catch (err) {
return res.status(500).json({
message: 'Internal Server Error',
});
}
};