mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Ported contact REST API route to controllers dir
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
]
|
||||
}
|
||||
]
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user