Skip to content

[BE-67] Build Audit Log viewer endpoint — searchable, filterable history of all system changes #1037

Description

@yusuftomilola

Overview

While AssetHistory records exist for asset-level changes, there is no unified audit trail covering all entity types (users, departments, roles, locations). Compliance and security teams need a single endpoint to query what changed, who changed it, and when.

Context

  • An AuditLog entity may partially exist from prior PRs — verify before creating a new one
  • Every write operation across all modules should append an audit record
  • The endpoint must support pagination and multiple filter dimensions simultaneously

Acceptance Criteria

  • Create (or verify) AuditLog entity: id, entityType (e.g., asset, user, department), entityId, action (CREATED, UPDATED, DELETED, STATUS_CHANGED, ROLE_CHANGED), actorId (FK → User), previousValue (JSON), newValue (JSON), ipAddress, userAgent, createdAt
  • Create an AuditService.log() method and call it from AssetsService, UsersService, DepartmentsService, and AuthService on every mutating operation
  • GET /audit-logs (ADMIN only): accepts query params — entityType, entityId, actorId, action, from (date), to (date), page, limit
  • GET /audit-logs/:id — returns full detail of a single log entry including the JSON diff
  • Response includes actor's firstName and lastName (not just ID)
  • Apply caching with a short TTL (30 seconds) on the list endpoint

Metadata

Metadata

Assignees

No one assigned

    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