b22e5baa5c
Build and Push Docker Image / build (push) Successful in 1m23s
- Implemented client-side validation functions for tax ID, VAT ID, IBAN, BIC, and website URL. - Added debug logging functionality to assist in development. - Created a comprehensive validation function for company form data. feat: initialize database with Prisma migrations - Added a server-side script to run Prisma migrations and check database health. - Ensured safe initialization of the database to prevent concurrent migrations. feat: comprehensive server-side error logging - Developed an error logging system that captures detailed error context, including request details and stack traces. - Implemented logging functions for different error types (route, action, database, API, startup). fix: validate user ID existence in audit logs - Updated the logging function to validate that the user ID exists in the database before logging actions. fix: update schemas for optional fields and validation - Modified schemas to allow for nullable fields and refined validation logic for tax ID, VAT ID, IBAN, and BIC. feat: enhance error boundary for better debugging - Improved error boundary to log detailed error information in development mode. - Added a debug panel to the main application layout for real-time error tracking. feat: implement company deletion functionality in admin routes - Added a new API route for deleting companies with appropriate logging. - Integrated delete confirmation in the admin interface for better user experience. fix: handle API errors gracefully - Wrapped API actions in try-catch blocks to log errors and return appropriate responses. feat: generate and save invoice PDFs - Implemented functionality to generate and save invoice PDFs upon status updates. - Added a new column in the database for storing the URL of the generated PDF. chore: update Docker image reference - Changed the Docker image reference to point to the new Git repository. chore: update package dependencies - Added @radix-ui/react-tooltip for enhanced UI components. - Updated package-lock.json to reflect new dependencies.
81 lines
1.9 KiB
TypeScript
81 lines
1.9 KiB
TypeScript
import prisma from "@/lib/prisma.server";
|
|
|
|
export type LogAction =
|
|
| "LOGIN"
|
|
| "LOGIN_FAILED"
|
|
| "LOGOUT"
|
|
| "CHANGE_PASSWORD"
|
|
| "CREATE_USER"
|
|
| "UPDATE_USER"
|
|
| "DELETE_USER"
|
|
| "CREATE_COMPANY"
|
|
| "UPDATE_COMPANY"
|
|
| "DELETE_COMPANY"
|
|
| "ARCHIVE_COMPANY"
|
|
| "CREATE_INVOICE"
|
|
| "UPDATE_INVOICE"
|
|
| "DELETE_INVOICE"
|
|
| "UPDATE_INVOICE_STATUS"
|
|
| "CREATE_CUSTOMER"
|
|
| "UPDATE_CUSTOMER"
|
|
| "DELETE_CUSTOMER"
|
|
| "CREATE_SERVICE"
|
|
| "UPDATE_SERVICE"
|
|
| "DELETE_SERVICE"
|
|
| "UPLOAD_BELEG"
|
|
| "DELETE_BELEG";
|
|
|
|
export async function log({
|
|
userId,
|
|
action,
|
|
entity,
|
|
entityId,
|
|
metadata,
|
|
request,
|
|
}: {
|
|
userId?: string | null;
|
|
action: LogAction;
|
|
entity?: string;
|
|
entityId?: string;
|
|
metadata?: Record<string, unknown>;
|
|
request?: Request;
|
|
}) {
|
|
const ipAddress = request
|
|
? request.headers.get("x-forwarded-for") ??
|
|
request.headers.get("x-real-ip") ??
|
|
undefined
|
|
: undefined;
|
|
|
|
try {
|
|
// Validate that userId exists in the database if provided
|
|
let validatedUserId = userId;
|
|
if (userId) {
|
|
const userExists = await prisma.user.findUnique({
|
|
where: { id: userId },
|
|
select: { id: true },
|
|
});
|
|
if (!userExists) {
|
|
validatedUserId = null; // User doesn't exist, log as anonymous
|
|
}
|
|
}
|
|
|
|
await prisma.auditLog.create({
|
|
data: {
|
|
userId: validatedUserId ?? null,
|
|
action,
|
|
entity: entity ?? null,
|
|
entityId: entityId ?? null,
|
|
metadata: (metadata as any) ?? undefined,
|
|
ipAddress: ipAddress ?? null,
|
|
},
|
|
});
|
|
} catch (err) {
|
|
// Never let logging failures break the app
|
|
console.error("[AuditLog] Failed to write log entry:", err);
|
|
}
|
|
|
|
console.log(
|
|
`[AUDIT] ${new Date().toISOString()} | ${action}${entity ? ` | ${entity}` : ""}${entityId ? `:${entityId}` : ""}${userId ? ` | user:${userId}` : ""}${ipAddress ? ` | ip:${ipAddress}` : ""}`
|
|
);
|
|
}
|