Skip to main content

Anomalies

Handles anomaly reports from frontend, storing encrypted images or audio files in Google Cloud Storage and recording metadata for each anomaly.

🗂️ Structure

anomalies/
├── controllers/
│ └── AnomalyController.ts # API routes to record/retrieve anomalies
├── services/
│ ├── AnomalyService.ts # Business logic for anomaly data
│ └── CloudStorageService.ts # Upload/download/delete files from GCS
├── classes/
│ ├── validators/ # DTOs and validation for requests
│ └── transformers/ # Response formatting and stats helpers
├── abilities/ # CASL permission logic
├── types.ts # Inversify DI tokens
└── container.ts # DI bindings

🎯 Key Features

  • Record anomalies (image/audio) and store in GCS
  • Validate file metadata and save info in DB
  • Fetch anomalies for user, item, or entire course
  • Generate stats (blur, face, voice, etc.)
  • Signed URLs for secure access to uploaded media
  • Transactional writes with rollback safety

🔁 Workflow

  • Frontend sends file + anomaly metadata to API
  • AnomalyController validates and delegates to AnomalyService
  • AnomalyService:
    • Confirms course/version integrity
    • Uploads file via CloudStorageService
    • Stores anomaly metadata in MongoDB (within transaction)
    • Returns sanitized response (no file path, just data)

🛠 Services Involved

  • AnomalyService: Coordinates file upload, validation, DB save, and anomaly retrieval. All DB interactions wrapped in transactions.
  • CloudStorageService: Handles file uploads/deletes with timestamped filenames, signed access URLs, and organized storage paths (userId/type/timestamp.ext).