feat(center): add audit logs for auth and node operations

This commit is contained in:
nav
2026-05-12 08:57:34 +00:00
parent 7f68a09486
commit 7270256587
8 changed files with 131 additions and 3 deletions

View File

@@ -0,0 +1,12 @@
import { Global, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuditLog } from '../entities/audit-log.entity';
import { AuditService } from './audit.service';
@Global()
@Module({
imports: [TypeOrmModule.forFeature([AuditLog])],
providers: [AuditService],
exports: [AuditService],
})
export class AuditModule {}

View File

@@ -0,0 +1,31 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AuditLog } from '../entities/audit-log.entity';
export type AuditWriteInput = {
action: string;
actorId?: string | null;
targetType?: string | null;
targetId?: string | null;
detail?: string | null;
};
@Injectable()
export class AuditService {
constructor(
@InjectRepository(AuditLog)
private readonly auditRepo: Repository<AuditLog>,
) {}
async write(input: AuditWriteInput): Promise<void> {
const row = this.auditRepo.create({
action: input.action,
actorId: input.actorId ?? null,
targetType: input.targetType ?? null,
targetId: input.targetId ?? null,
detail: input.detail ?? null,
});
await this.auditRepo.save(row);
}
}