Skip to content

[BE-24] Implement asset history and audit trail — GET /assets/:id/history #897

Description

@yusuftomilola

Overview

The asset detail page (frontend/app/(dashboard)/assets/[id]/page.tsx) has a "History" tab that calls GET /assets/:id/history and renders a timeline of all events on the asset. Every create, update, status change, transfer, maintenance event, note, and document upload must be captured.

Context

  • Frontend: frontend/lib/api/assets.ts getAssetHistory(id) calls GET /assets/:id/history
  • Frontend type: AssetHistoryEvent.action enum in frontend/lib/query/types/asset.ts: CREATED, UPDATED, STATUS_CHANGED, TRANSFERRED, MAINTENANCE, NOTE_ADDED, DOCUMENT_UPLOADED
  • History records are write-only — they must never be updated or deleted (immutable audit trail)

Acceptance Criteria

  • Create AssetHistory entity: id (UUID), assetId, action (AssetHistoryAction enum), userId (who performed the action), metadata (JSON — stores before/after values or relevant context), createdAt
  • Create AssetHistoryAction enum matching the frontend: CREATED, UPDATED, STATUS_CHANGED, TRANSFERRED, MAINTENANCE, NOTE_ADDED, DOCUMENT_UPLOADED
  • GET /assets/:id/history returns paginated history records sorted by createdAt DESC, with user firstName and lastName included (JOIN, not N+1)
  • Create AssetHistoryService.log(assetId, action, userId, metadata?) as a reusable method called from AssetsService, NotesService, MaintenanceService, DocumentService
  • Add @Index() on AssetHistory.assetId and AssetHistory.createdAt

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

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