Template base para proyectos SaaS multi-tenant. Estructura inicial: - apps/backend (NestJS API) - apps/frontend (React/Vite) - apps/database (PostgreSQL DDL) - docs/ (Documentación) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
62 lines
2.3 KiB
TypeScript
62 lines
2.3 KiB
TypeScript
import { Repository } from 'typeorm';
|
|
import { AuditLog, AuditAction } from '../entities/audit-log.entity';
|
|
import { ActivityLog, ActivityType } from '../entities/activity-log.entity';
|
|
import { QueryAuditLogsDto } from '../dto/query-audit.dto';
|
|
import { QueryActivityLogsDto } from '../dto/query-activity.dto';
|
|
import { CreateActivityLogDto } from '../dto/create-activity.dto';
|
|
export interface CreateAuditLogParams {
|
|
tenant_id: string;
|
|
user_id?: string;
|
|
action: AuditAction;
|
|
entity_type: string;
|
|
entity_id?: string;
|
|
old_values?: Record<string, any>;
|
|
new_values?: Record<string, any>;
|
|
ip_address?: string;
|
|
user_agent?: string;
|
|
endpoint?: string;
|
|
http_method?: string;
|
|
response_status?: number;
|
|
duration_ms?: number;
|
|
description?: string;
|
|
metadata?: Record<string, any>;
|
|
}
|
|
export interface PaginatedResult<T> {
|
|
data: T[];
|
|
total: number;
|
|
page: number;
|
|
limit: number;
|
|
totalPages: number;
|
|
}
|
|
export declare class AuditService {
|
|
private readonly auditLogRepository;
|
|
private readonly activityLogRepository;
|
|
constructor(auditLogRepository: Repository<AuditLog>, activityLogRepository: Repository<ActivityLog>);
|
|
createAuditLog(params: CreateAuditLogParams): Promise<AuditLog>;
|
|
queryAuditLogs(tenantId: string, query: QueryAuditLogsDto): Promise<PaginatedResult<AuditLog>>;
|
|
getAuditLogById(tenantId: string, id: string): Promise<AuditLog | null>;
|
|
getEntityAuditHistory(tenantId: string, entityType: string, entityId: string): Promise<AuditLog[]>;
|
|
createActivityLog(tenantId: string, userId: string, dto: CreateActivityLogDto, context?: {
|
|
ip_address?: string;
|
|
user_agent?: string;
|
|
session_id?: string;
|
|
}): Promise<ActivityLog>;
|
|
queryActivityLogs(tenantId: string, query: QueryActivityLogsDto): Promise<PaginatedResult<ActivityLog>>;
|
|
getUserActivitySummary(tenantId: string, userId: string, days?: number): Promise<{
|
|
activity_type: ActivityType;
|
|
count: number;
|
|
}[]>;
|
|
getAuditStats(tenantId: string, days?: number): Promise<{
|
|
total_actions: number;
|
|
actions_by_type: {
|
|
action: AuditAction;
|
|
count: number;
|
|
}[];
|
|
top_users: {
|
|
user_id: string;
|
|
count: number;
|
|
}[];
|
|
}>;
|
|
private detectChangedFields;
|
|
}
|