Skip to content

[BE-67] Create AuditLog entity and AuditService for tracking sensitive operations #791

Description

@mftee

Overview

SMALDA handles legal land documents where accountability is critical. There is no audit trail for sensitive operations: who uploaded a document, who deleted it, when a user's role was changed. An audit log provides forensic traceability and is a baseline requirement for any platform dealing with land records.

Background

Files to create:

  • backend/src/audit/entities/audit-log.entity.ts
  • backend/src/audit/audit.service.ts
  • backend/src/audit/audit.module.ts

AuditLog entity fields:

  • id (UUID)
  • actorId (UUID — the user who performed the action, nullable for system actions)
  • actorRole (string — snapshot of role at time of action)
  • action: enum DOCUMENT_UPLOAD | DOCUMENT_DELETE | DOCUMENT_VERIFY | DOCUMENT_ARCHIVE | USER_ROLE_CHANGE | USER_DELETE | DISPUTE_CREATED | DISPUTE_RESOLVED
  • targetType (string — e.g., 'Document', 'User')
  • targetId (UUID)
  • metadata (JSON — optional extra context, e.g., old vs new role)
  • ipAddress (string)
  • createdAt (timestamp)

AuditService methods:

  • log(dto: CreateAuditLogDto) — insert a record
  • findAll(filters, pagination) — for the admin endpoint

Acceptance Criteria

  • Entity defined with all fields and action enum
  • Migration generated for the audit_logs table
  • AuditService.log() called in: DocumentsService.create(), DocumentsService.delete(), StellarService.anchorHash(), UsersService role change
  • AuditModule created and imported in AppModule
  • AuditService exported for injection by other modules

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions