attack-workbench-rest-api
attack-workbench-rest-api copied to clipboard
Refactor Recent Activity Service for Improved Structure and Asynchronicity
Refactor recentActivityService for Improved Structure and Asynchronicity
Description:
In line with our project-orion objectives, the following requirements should be addressed for the recent-activity-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:
-
Decoupling Database Logic:
- Remove all direct database operations from the service module.
- Migrate these operations to a new repository/DAO module.
-
Exceptions Handling:
- Implement the new exceptions module to handle errors.
- Replace traditional error handling with our standardized custom error classes.
-
Callbacks to Promises:
- Transition all existing callback handlers to Promises.
- Use
try-catchblocks andasync/awaitnotation for cleaner, more readable asynchronous code.
-
Service Structure:
- Refactor the service module to be a class-based structure.
- This class should extend the
BaseServicefor consistent behavior and structure across all services.
-
Repository Structure:
- The newly created repository/DAO should also be class-based.
- This class should extend the
BaseRepositoryto ensure consistency in database operations across services.
-
Common Function Migration:
- Migrate shared or common functions to
BaseRepositoryandBaseServiceas necessary. - Avoid duplication and ensure that common functionalities are accessible to all services and repositories.
- Migrate shared or common functions to
-
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.
- 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
-
Testing:
- Refactor the Mocha test suite spec file corresponding to this service.
- Transition from callbacks to
async/awaitnotation. - 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.