Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
@@ -1,39 +1,22 @@
|
||||
import { Tenant, Log, ApiKey, Prisma } from "@toolctrl/db/prisma-browser";
|
||||
import { Tenant, Log, ApiKey } from "@hivegrid/db/prisma-browser";
|
||||
import { FiltersDto } from "~/application/dtos/data/FiltersDto";
|
||||
import { PaginationDto } from "~/application/dtos/data/PaginationDto";
|
||||
import { DefaultLogActions } from "~/application/dtos/shared/DefaultLogActions";
|
||||
import { db } from "../db.server";
|
||||
import ApiHelper from "../helpers/ApiHelper";
|
||||
import RowFiltersHelper from "../helpers/RowFiltersHelper";
|
||||
import { getUserInfo } from "../session.server";
|
||||
import { EntityWithDetails } from "./entities/entities.db.server";
|
||||
import { callEntityWebhooks } from "./entities/entityWebhooks.db.server";
|
||||
import { RowCommentWithDetails } from "./entities/rowComments.db.server";
|
||||
import { RowWithDetails } from "./entities/rows.db.server";
|
||||
import { UserWithoutPassword } from "./users.db.server";
|
||||
import UserModelHelper from "../helpers/models/UserModelHelper";
|
||||
|
||||
export type LogWithDetails = Log & {
|
||||
user: UserWithoutPassword | null;
|
||||
apiKey: ApiKey | null;
|
||||
tenant?: Tenant | null;
|
||||
comment?: RowCommentWithDetails | null;
|
||||
};
|
||||
|
||||
const include = {
|
||||
user: true,
|
||||
tenant: true,
|
||||
apiKey: true,
|
||||
comment: {
|
||||
include: {
|
||||
...UserModelHelper.includeSimpleCreatedByUser,
|
||||
reactions: {
|
||||
include: {
|
||||
...UserModelHelper.includeSimpleCreatedByUser,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export async function getAllLogs(
|
||||
@@ -89,73 +72,6 @@ export async function getLogs(
|
||||
};
|
||||
}
|
||||
|
||||
export async function getAllRowLogs({
|
||||
entityId,
|
||||
rowId,
|
||||
tenantId,
|
||||
pagination,
|
||||
}: {
|
||||
entityId?: string;
|
||||
rowId?: string;
|
||||
tenantId?: string | null;
|
||||
pagination: { page: number; pageSize: number };
|
||||
}): Promise<{ items: LogWithDetails[]; pagination: PaginationDto }> {
|
||||
let where: Prisma.LogWhereInput = { rowId: { not: null } };
|
||||
if (entityId) {
|
||||
where = { ...where, row: { entityId } };
|
||||
}
|
||||
if (rowId) {
|
||||
where = { ...where, rowId };
|
||||
}
|
||||
if (tenantId !== undefined) {
|
||||
where = { ...where, tenantId };
|
||||
}
|
||||
const items = await db.log.findMany({
|
||||
take: pagination.pageSize,
|
||||
skip: pagination.pageSize * (pagination.page - 1),
|
||||
where,
|
||||
include,
|
||||
});
|
||||
const totalItems = await db.log.count({
|
||||
where,
|
||||
});
|
||||
|
||||
return {
|
||||
items,
|
||||
pagination: {
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
totalItems,
|
||||
totalPages: Math.ceil(totalItems / pagination.pageSize),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function getRowLogs(tenantId: string | null, rowId: string): Promise<LogWithDetails[]> {
|
||||
return await db.log.findMany({
|
||||
where: {
|
||||
tenantId,
|
||||
rowId,
|
||||
},
|
||||
include,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getRowLogsById(rowId: string): Promise<LogWithDetails[]> {
|
||||
return await db.log.findMany({
|
||||
where: {
|
||||
rowId,
|
||||
},
|
||||
include,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function createLog(request: Request, tenantId: string | null, action: string, details: string) {
|
||||
const userInfo = await getUserInfo(request);
|
||||
await db.log.create({
|
||||
@@ -181,78 +97,6 @@ export async function createManualLog(userId: string, tenantId: string | null, p
|
||||
});
|
||||
}
|
||||
|
||||
export async function createRowLog(
|
||||
request: Request,
|
||||
data: {
|
||||
tenantId: string | null;
|
||||
createdByUserId?: string | null;
|
||||
createdByApiKey?: string | null;
|
||||
action: string;
|
||||
entity: EntityWithDetails;
|
||||
item: RowWithDetails | null;
|
||||
commentId?: string | null;
|
||||
details?: string;
|
||||
}
|
||||
) {
|
||||
const log = await db.log.create({
|
||||
data: {
|
||||
tenantId: data.tenantId,
|
||||
userId: data.createdByUserId ?? null,
|
||||
apiKeyId: data.createdByApiKey ?? null,
|
||||
url: new URL(request.url).pathname,
|
||||
rowId: data.item?.id ?? null,
|
||||
action: data.action,
|
||||
details: data.details ?? null,
|
||||
commentId: data.commentId ?? null,
|
||||
},
|
||||
});
|
||||
const apiFormat = ApiHelper.getApiFormat(data.entity, data.item);
|
||||
await callEntityWebhooks({
|
||||
logId: log.id,
|
||||
entityId: data.entity.id,
|
||||
action: data.action,
|
||||
body: apiFormat,
|
||||
request,
|
||||
});
|
||||
return log;
|
||||
}
|
||||
|
||||
export async function createManualRowLog(
|
||||
data: {
|
||||
tenantId: string | null;
|
||||
createdByUserId?: string | null;
|
||||
createdByApiKey?: string | null;
|
||||
action: string;
|
||||
entity: EntityWithDetails;
|
||||
item: RowWithDetails | null;
|
||||
commentId?: string | null;
|
||||
},
|
||||
request?: Request
|
||||
) {
|
||||
let details = "";
|
||||
const log = await db.log.create({
|
||||
data: {
|
||||
tenantId: data.tenantId,
|
||||
userId: data.createdByUserId ?? null,
|
||||
apiKeyId: data.createdByApiKey ?? null,
|
||||
url: request ? new URL(request.url).pathname : "",
|
||||
rowId: data.item?.id ?? null,
|
||||
action: data.action,
|
||||
details,
|
||||
commentId: data.commentId ?? null,
|
||||
},
|
||||
});
|
||||
const apiFormat = ApiHelper.getApiFormat(data.entity, data.item);
|
||||
await callEntityWebhooks({
|
||||
logId: log.id,
|
||||
entityId: data.entity.id,
|
||||
action: data.action,
|
||||
body: apiFormat,
|
||||
// request,
|
||||
});
|
||||
return log;
|
||||
}
|
||||
|
||||
export async function createLogLogin(request: Request, user: UserWithoutPassword) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log({ clientIpAddress: getClientIPAddress(request.headers) });
|
||||
|
||||
Reference in new issue
Block a user