diff --git a/src/modules/contact/controller.js b/src/controllers/rest-api/contact/controller.js similarity index 94% rename from src/modules/contact/controller.js rename to src/controllers/rest-api/contact/controller.js index 846e66b..b5b94b5 100644 --- a/src/modules/contact/controller.js +++ b/src/controllers/rest-api/contact/controller.js @@ -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 diff --git a/src/controllers/rest-api/contact/index.js b/src/controllers/rest-api/contact/index.js new file mode 100644 index 0000000..3ea84eb --- /dev/null +++ b/src/controllers/rest-api/contact/index.js @@ -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 diff --git a/src/controllers/rest-api/contact/router.js b/src/controllers/rest-api/contact/router.js new file mode 100644 index 0000000..02914f9 --- /dev/null +++ b/src/controllers/rest-api/contact/router.js @@ -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 diff --git a/src/controllers/rest-api/index.js b/src/controllers/rest-api/index.js index 4bd1e34..b0c8628 100644 --- a/src/controllers/rest-api/index.js +++ b/src/controllers/rest-api/index.js @@ -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. diff --git a/src/modules/contact/router.js b/src/modules/contact/router.js deleted file mode 100644 index 0f0bf3c..0000000 --- a/src/modules/contact/router.js +++ /dev/null @@ -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 - ] - } -] diff --git a/test/e2e/automated/temp/a04-contact.rest-e2e.js b/test/e2e/automated/a04-contact.rest-e2e.js similarity index 98% rename from test/e2e/automated/temp/a04-contact.rest-e2e.js rename to test/e2e/automated/a04-contact.rest-e2e.js index bfc72ca..4d28cde 100644 --- a/test/e2e/automated/temp/a04-contact.rest-e2e.js +++ b/test/e2e/automated/a04-contact.rest-e2e.js @@ -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 diff --git a/test/unit/rest-api/a04-contact.rest-api.js b/test/unit/rest-api/a04-contact.rest-api.js index 874634c..e8c721d 100644 --- a/test/unit/rest-api/a04-contact.rest-api.js +++ b/test/unit/rest-api/a04-contact.rest-api.js @@ -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()