documenso/packages/lib/server-only/webhooks/edit-webhook.ts

30 lines
723 B
TypeScript
Raw Normal View History

2024-02-14 12:38:58 +00:00
import type { Prisma } from '@prisma/client';
import { prisma } from '@documenso/prisma';
2025-06-10 01:49:52 +00:00
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '../../constants/teams';
import { buildTeamWhereQuery } from '../../utils/teams';
2024-02-14 12:38:58 +00:00
export type EditWebhookOptions = {
2024-02-27 01:13:56 +00:00
id: string;
2024-02-27 05:56:32 +00:00
data: Omit<Prisma.WebhookUpdateInput, 'id' | 'userId' | 'teamId'>;
2024-02-14 12:38:58 +00:00
userId: number;
2025-06-10 01:49:52 +00:00
teamId: number;
2024-02-14 12:38:58 +00:00
};
2024-02-27 05:56:32 +00:00
export const editWebhook = async ({ id, data, userId, teamId }: EditWebhookOptions) => {
2024-02-14 12:38:58 +00:00
return await prisma.webhook.update({
where: {
id,
2025-06-10 01:49:52 +00:00
team: buildTeamWhereQuery({
teamId,
userId,
roles: TEAM_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_TEAM'],
}),
2024-02-14 12:38:58 +00:00
},
data: {
...data,
},
});
};