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')
|
2021-07-12 17:37:49 -07:00
|
|
|
const UserRouter = require('./users')
|
2021-07-06 14:33:54 -07:00
|
|
|
const ContactRESTController = require('./contact')
|
2021-07-06 14:47:43 -07:00
|
|
|
const LogsRESTController = require('./logs')
|
2021-07-05 19:36:56 -07:00
|
|
|
|
2021-07-06 19:29:49 -07:00
|
|
|
class RESTControllers {
|
2021-07-12 17:37:49 -07:00
|
|
|
constructor (localConfig = {}) {
|
2021-07-06 19:29:49 -07:00
|
|
|
// Dependency Injection.
|
|
|
|
|
this.adapters = localConfig.adapters
|
|
|
|
|
if (!this.adapters) {
|
|
|
|
|
throw new Error(
|
2021-07-12 17:37:49 -07:00
|
|
|
'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(
|
2021-07-12 17:37:49 -07:00
|
|
|
'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
|
2021-07-12 17:37:49 -07:00
|
|
|
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
|