center-for-threat-informed-defense / attack-workbench-rest-api

An application allowing users to explore, create, annotate, and share extensions of the MITRE ATT&CK® knowledge base. This repository contains the REST API service for storing, querying, and editing ATT&CK objects.
https://ctid.mitre-engenuity.org/
Apache License 2.0
42 stars 22 forks source link

Refactor Campaigns Service for Improved Structure and Asynchronicity #306

Closed seansica closed 10 months ago

seansica commented 1 year ago

Refactor campaignsService for Improved Structure and Asynchronicity

Description:

In line with our project-orion objectives, the following requirements should be addressed for the campaigns-service.js module. Please use the Matrices service and repository (services/matrices-service.js and repository/matrices-repository.js) as a frame of reference when making these changes.

Requirements:

  1. Decoupling Database Logic:

    • Remove all direct database operations from the service module.
    • Migrate these operations to a new repository/DAO module.
  2. Exceptions Handling:

    • Implement the new exceptions module to handle errors.
    • Replace traditional error handling with our standardized custom error classes.
  3. Callbacks to Promises:

    • Transition all existing callback handlers to Promises.
    • Use try-catch blocks and async/await notation for cleaner, more readable asynchronous code.
  4. Service Structure:

    • Refactor the service module to be a class-based structure.
    • This class should extend the BaseService for consistent behavior and structure across all services.
  5. Repository Structure:

    • The newly created repository/DAO should also be class-based.
    • This class should extend the BaseRepository to ensure consistency in database operations across services.
  6. Common Function Migration:

    • Migrate shared or common functions to BaseRepository and BaseService as necessary.
    • Avoid duplication and ensure that common functionalities are accessible to all services and repositories.
  7. Service-Specific Functions:

    • Functions that are specific to a particular service and are not shared should be implemented directly on the corresponding service class. Do not add them to BaseRepository.
  8. Testing:

    • Refactor the Mocha test suite spec file corresponding to this service.
    • Transition from callbacks to async/await notation.
    • Ensure all tests are passing before opening a pull request.

Notes:

Please reference any relevant documentation, discussions, or PRs as needed. Ensure that the refactoring remains consistent with the established practices from the Matrices service and repository as a reference.