mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-22 09:11:59 -07:00
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
/*
|
|
REST API library for /entry route.
|
|
*/
|
|
|
|
// Public npm libraries.
|
|
import Router from 'koa-router'
|
|
|
|
// Local libraries.
|
|
import EntryRESTControllerLib from './controller.js'
|
|
|
|
let _this
|
|
|
|
class UserRouter {
|
|
constructor (localConfig = {}) {
|
|
// Dependency Injection.
|
|
this.adapters = localConfig.adapters
|
|
if (!this.adapters) {
|
|
throw new Error(
|
|
'Instance of Adapters library required when instantiating /entry REST Controller.'
|
|
)
|
|
}
|
|
this.useCases = localConfig.useCases
|
|
if (!this.useCases) {
|
|
throw new Error(
|
|
'Instance of Use Cases library required when instantiating /entry REST Controller.'
|
|
)
|
|
}
|
|
|
|
const dependencies = {
|
|
adapters: this.adapters,
|
|
useCases: this.useCases
|
|
}
|
|
|
|
// Encapsulate dependencies.
|
|
this.entryRESTController = new EntryRESTControllerLib(dependencies)
|
|
|
|
// Instantiate the router and set the base route.
|
|
const baseUrl = '/entry'
|
|
this.router = new Router({ prefix: baseUrl })
|
|
|
|
_this = this
|
|
}
|
|
|
|
attach (app) {
|
|
if (!app) {
|
|
throw new Error(
|
|
'Must pass app object when attaching REST API controllers.'
|
|
)
|
|
}
|
|
|
|
// Define the routes and attach the controller.
|
|
this.router.post('/', _this.entryRESTController.createEntry)
|
|
|
|
// Attach the Controller routes to the Koa app.
|
|
app.use(_this.router.routes())
|
|
app.use(_this.router.allowedMethods())
|
|
}
|
|
}
|
|
|
|
export default UserRouter
|