mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign). Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files) and align docker/Dockerfile turbo --scope/--filter to the actual remix package name @hanzo/esign (was a pre-existing mismatch with -remix that broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
84 lines
1.9 KiB
TypeScript
84 lines
1.9 KiB
TypeScript
import { Prisma, WebhookCallStatus, WebhookTriggerEvents } from '@prisma/client';
|
|
|
|
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '@hanzo/esign-lib/constants/teams';
|
|
import { AppError, AppErrorCode } from '@hanzo/esign-lib/errors/app-error';
|
|
import type { FindResultResponse } from '@hanzo/esign-lib/types/search-params';
|
|
import { buildTeamWhereQuery } from '@hanzo/esign-lib/utils/teams';
|
|
import { prisma } from '@hanzo/esign-prisma';
|
|
|
|
import {
|
|
ZFindWebhookCallsRequestSchema,
|
|
ZFindWebhookCallsResponseSchema,
|
|
} from './find-webhook-calls.types';
|
|
|
|
type FindWebhookCallsOptions = {
|
|
userId: number;
|
|
teamId: number;
|
|
webhookId: string;
|
|
page?: number;
|
|
perPage?: number;
|
|
status?: WebhookCallStatus;
|
|
events?: WebhookTriggerEvents[];
|
|
query?: string;
|
|
};
|
|
|
|
export const findWebhookCalls = async ({
|
|
userId,
|
|
teamId,
|
|
webhookId,
|
|
page = 1,
|
|
perPage = 20,
|
|
events,
|
|
query = '',
|
|
status,
|
|
}: FindWebhookCallsOptions) => {
|
|
const webhook = await prisma.webhook.findFirst({
|
|
where: {
|
|
id: webhookId,
|
|
team: buildTeamWhereQuery({
|
|
teamId,
|
|
userId,
|
|
roles: TEAM_MEMBER_ROLE_PERMISSIONS_MAP.MANAGE_TEAM,
|
|
}),
|
|
},
|
|
});
|
|
|
|
if (!webhook) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND);
|
|
}
|
|
|
|
const whereClause: Prisma.WebhookCallWhereInput = {
|
|
webhookId: webhook.id,
|
|
status,
|
|
id: query || undefined,
|
|
event:
|
|
events && events.length > 0
|
|
? {
|
|
in: events,
|
|
}
|
|
: undefined,
|
|
};
|
|
|
|
const [data, count] = await Promise.all([
|
|
prisma.webhookCall.findMany({
|
|
where: whereClause,
|
|
skip: Math.max(page - 1, 0) * perPage,
|
|
take: perPage,
|
|
orderBy: {
|
|
createdAt: 'desc',
|
|
},
|
|
}),
|
|
prisma.webhookCall.count({
|
|
where: whereClause,
|
|
}),
|
|
]);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
currentPage: Math.max(page, 1),
|
|
perPage,
|
|
totalPages: Math.ceil(count / perPage),
|
|
} satisfies FindResultResponse<typeof data>;
|
|
};
|