Files
bch-dex/src/controllers/rest-api/index.js
T

59 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-07-05 19:36:56 -07:00
/*
This index file for the Clean Architecture Controllers loads dependencies,
creates instances, and attaches the controller to REST API endpoints for
Koa.
*/
// Public npm libraries.
// Load the REST API Controllers.
const AuthRESTController = require('./auth')
const UserRouter = require('./users')
const ContactRESTController = require('./contact')
const LogsRESTController = require('./logs')
2021-07-05 19:36:56 -07:00
2021-07-06 19:29:49 -07:00
class RESTControllers {
constructor (localConfig = {}) {
2021-07-06 19:29:49 -07:00
// Dependency Injection.
this.adapters = localConfig.adapters
if (!this.adapters) {
throw new Error(
'Instance of Adapters library required when instantiating REST Controller libraries.'
2021-07-06 19:29:49 -07:00
)
}
this.useCases = localConfig.useCases
if (!this.useCases) {
throw new Error(
'Instance of Use Cases library required when instantiating REST Controller libraries.'
2021-07-06 19:29:49 -07:00
)
}
2021-07-10 09:04:03 -07:00
// console.log('Controllers localConfig: ', localConfig)
2021-07-06 19:29:49 -07:00
}
attachRESTControllers (app) {
const dependencies = {
adapters: this.adapters,
useCases: this.useCases
}
// Attach the REST API Controllers associated with the /auth route
const authRESTController = new AuthRESTController(dependencies)
authRESTController.attach(app)
// Attach the REST API Controllers associated with the /user route
const userRouter = new UserRouter(dependencies)
userRouter.attach(app)
2021-07-06 19:29:49 -07:00
// Attach the REST API Controllers associated with the /contact route
const contactRESTController = new ContactRESTController(dependencies)
contactRESTController.attach(app)
// Attach the REST API Controllers associated with the /logs route
const logsRESTController = new LogsRESTController(dependencies)
logsRESTController.attach(app)
}
2021-07-05 19:36:56 -07:00
}
2021-07-06 19:29:49 -07:00
module.exports = RESTControllers