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.
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import type { UserSecurityAuditLog, UserSecurityAuditLogType } from '@prisma/client';
|
|
|
|
import { prisma } from '@hanzo/esign-prisma';
|
|
|
|
import type { FindResultResponse } from '../../types/search-params';
|
|
|
|
export type FindUserSecurityAuditLogsOptions = {
|
|
userId: number;
|
|
type?: UserSecurityAuditLogType;
|
|
page?: number;
|
|
perPage?: number;
|
|
orderBy?: {
|
|
column: keyof Omit<UserSecurityAuditLog, 'id' | 'userId'>;
|
|
direction: 'asc' | 'desc';
|
|
};
|
|
};
|
|
|
|
export const findUserSecurityAuditLogs = async ({
|
|
userId,
|
|
type,
|
|
page = 1,
|
|
perPage = 10,
|
|
orderBy,
|
|
}: FindUserSecurityAuditLogsOptions) => {
|
|
const orderByColumn = orderBy?.column ?? 'createdAt';
|
|
const orderByDirection = orderBy?.direction ?? 'desc';
|
|
|
|
const whereClause = {
|
|
userId,
|
|
type,
|
|
};
|
|
|
|
const [data, count] = await Promise.all([
|
|
prisma.userSecurityAuditLog.findMany({
|
|
where: whereClause,
|
|
skip: Math.max(page - 1, 0) * perPage,
|
|
take: perPage,
|
|
orderBy: {
|
|
[orderByColumn]: orderByDirection,
|
|
},
|
|
}),
|
|
prisma.userSecurityAuditLog.count({
|
|
where: whereClause,
|
|
}),
|
|
]);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
currentPage: Math.max(page, 1),
|
|
perPage,
|
|
totalPages: Math.ceil(count / perPage),
|
|
} satisfies FindResultResponse<typeof data>;
|
|
};
|