Ported contact REST API route to controllers dir

This commit is contained in:
Chris Troutner
2021-07-06 14:33:54 -07:00
parent 089adfb40f
commit 8a37261995
7 changed files with 70 additions and 23 deletions
@@ -1,11 +1,11 @@
/*
Controller or the /contact REST API endpoints.
Controller for the /contact REST API endpoints.
*/
/* eslint-disable no-useless-escape */
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const ContactLib = require('../../lib/contact')
const ContactLib = require('../../../lib/contact')
const contactLib = new ContactLib()
let _this
+17
View File
@@ -0,0 +1,17 @@
/*
REST API library for /contact route.
*/
const ContactRESTRouter = require('./router')
class ContactRESTController {
constructor (localConfig = {}) {
this.contactRESTRouter = new ContactRESTRouter()
}
attach (app) {
this.contactRESTRouter.attachControllers(app)
}
}
module.exports = ContactRESTController
@@ -0,0 +1,43 @@
/*
REST Router for the /contact route.
*/
// Public npm libraries.
const Router = require('koa-router')
// Local libraries.
const ContactRESTControllerLib = require('./controller')
const Validators = require('../middleware/validators')
// let _this
class ContactRESTRouter {
constructor (localConfig = {}) {
// Encapsulate dependencies.
this.contactRESTController = new ContactRESTControllerLib()
this.validators = new Validators()
// Instantiate the router and set the base route.
const baseUrl = '/contact'
this.router = new Router({ prefix: baseUrl })
// _this = this
}
attachControllers (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('/email', this.contactRESTController.email)
// Attach the Controller routes to the Koa app.
app.use(this.router.routes())
app.use(this.router.allowedMethods())
}
}
module.exports = ContactRESTRouter
+5
View File
@@ -12,6 +12,7 @@
// const PostWebhook = require('./rest/post-webhook')
const AuthRESTController = require('./auth')
const UserRESTController = require('./users')
const ContactRESTController = require('./contact')
// Load the Clean Architecture Adapters library
// const adapters = require('../adapters')
@@ -47,6 +48,10 @@ function attachRESTControllers (app) {
// Attach the REST API Controllers associated with the /user route
const userRESTController = new UserRESTController()
userRESTController.attach(app)
// Attach the REST API Controllers associated with the /contact route
const contactRESTController = new ContactRESTController()
contactRESTController.attach(app)
}
// Add the JSON RPC router to the ipfs-coord adapter.
-17
View File
@@ -1,17 +0,0 @@
// const ensureUser = require('../../midleware/validators')
const ContactController = require('./controller')
const contactController = new ContactController()
// export const baseUrl = '/users'
module.exports.baseUrl = '/contact'
module.exports.routes = [
{
method: 'POST',
route: '/email',
handlers: [
contactController.email
]
}
]
@@ -9,7 +9,7 @@ const sinon = require('sinon')
const LOCALHOST = `http://localhost:${config.port}`
const mockContext = require('../../unit/mocks/ctx-mock').context
const ContactController = require('../../../src/modules/contact/controller')
const ContactController = require('../../../src/controllers/rest-api/contact/controller')
let uut
let sandbox
+2 -3
View File
@@ -6,7 +6,7 @@
const assert = require('chai').assert
const sinon = require('sinon')
const ContactController = require('../../../src/modules/contact/controller')
const ContactController = require('../../../src/controllers/rest-api/contact/controller')
let uut
let sandbox
let ctx
@@ -14,8 +14,7 @@ let ctx
const mockContext = require('../../unit/mocks/ctx-mock').context
describe('Contact', () => {
before(async () => {
})
before(async () => {})
beforeEach(() => {
uut = new ContactController()