2025-11-09 16:16:37 -08:00
|
|
|
/*
|
|
|
|
|
This index file for the Clean Architecture Controllers loads dependencies,
|
|
|
|
|
creates instances, and attaches the controller to REST API endpoints for
|
|
|
|
|
Express.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Local libraries
|
|
|
|
|
// import EventRouter from './event/index.js'
|
|
|
|
|
// import ReqRouter from './req/index.js'
|
2025-11-09 19:18:39 -08:00
|
|
|
import BlockchainRouter from './full-node/blockchain/index.js'
|
2025-11-09 16:16:37 -08:00
|
|
|
import config from '../../config/index.js'
|
|
|
|
|
|
|
|
|
|
class RESTControllers {
|
|
|
|
|
constructor (localConfig = {}) {
|
|
|
|
|
// Dependency Injection.
|
|
|
|
|
this.adapters = localConfig.adapters
|
|
|
|
|
if (!this.adapters) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'Instance of Adapters library required when instantiating REST Controller libraries.'
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
this.useCases = localConfig.useCases
|
|
|
|
|
if (!this.useCases) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'Instance of Use Cases library required when instantiating REST Controller libraries.'
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bind 'this' object to all subfunctions.
|
|
|
|
|
this.attachRESTControllers = this.attachRESTControllers.bind(this)
|
|
|
|
|
|
|
|
|
|
// Encapsulate dependencies
|
|
|
|
|
this.config = config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attachRESTControllers (app) {
|
2025-11-09 19:18:39 -08:00
|
|
|
const dependencies = {
|
|
|
|
|
adapters: this.adapters,
|
|
|
|
|
useCases: this.useCases
|
|
|
|
|
}
|
2025-11-09 16:16:37 -08:00
|
|
|
|
|
|
|
|
// Attach the REST API Controllers associated with the /event route
|
|
|
|
|
// const eventRouter = new EventRouter(dependencies)
|
|
|
|
|
// eventRouter.attach(app)
|
|
|
|
|
|
|
|
|
|
// Attach the REST API Controllers associated with the /req route
|
|
|
|
|
// const reqRouter = new ReqRouter(dependencies)
|
|
|
|
|
// reqRouter.attach(app)
|
2025-11-09 19:18:39 -08:00
|
|
|
|
|
|
|
|
const blockchainRouter = new BlockchainRouter(dependencies)
|
|
|
|
|
blockchainRouter.attach(app)
|
2025-11-09 16:16:37 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default RESTControllers
|