From 55f649cb1341d15006c4825ba39f00e7a703dc47 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 21 Jan 2019 18:09:09 -0800 Subject: [PATCH 1/8] Creating test scaffold --- config/env/development.js | 2 +- config/env/production.js | 2 +- config/env/test.js | 2 +- config/index.js | 2 +- package.json | 3 +- src/modules/iredmail/controller.js | 42 ++++++++++++++++++++++++ src/modules/iredmail/router.js | 14 ++++++++ test/a03-iredmail.spec.js | 52 ++++++++++++++++++++++++++++++ 8 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 src/modules/iredmail/controller.js create mode 100644 src/modules/iredmail/router.js create mode 100644 test/a03-iredmail.spec.js diff --git a/config/env/development.js b/config/env/development.js index 47f1615..d797fa3 100644 --- a/config/env/development.js +++ b/config/env/development.js @@ -9,5 +9,5 @@ export default { module.exports = { session: 'secret-boilerplate-token', token: 'secret-jwt-token', - database: 'mongodb://localhost:27017/p2pvps-server-dev' + database: 'mongodb://localhost:27017/iredmail-dev' } diff --git a/config/env/production.js b/config/env/production.js index a68e550..1364106 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -9,5 +9,5 @@ export default { module.exports = { session: 'secret-boilerplate-token', token: 'secret-jwt-token', - database: 'mongodb://localhost:27017/p2pvps-server-prod' + database: 'mongodb://localhost:27017/iredmail-prod' } diff --git a/config/env/test.js b/config/env/test.js index 9cc99f1..bcf077f 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -9,5 +9,5 @@ export default { module.exports = { session: 'secret-boilerplate-token', token: 'secret-jwt-token', - database: 'mongodb://localhost:27017/p2pvps-server-test' + database: 'mongodb://localhost:27017/irestmail-test' } diff --git a/config/index.js b/config/index.js index d8e1d3a..ed7edc8 100644 --- a/config/index.js +++ b/config/index.js @@ -7,7 +7,7 @@ try { } // Default to development environment. -const env = process.env.NODE_ENV || 'development' +const env = process.env.APP_ENV || 'development' // Load the config object for the selected environment. const config = require(`./env/${env}`) diff --git a/package.json b/package.json index 5222802..7f72bed 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "start": "node index.js", - "test": "NODE_ENV=test nyc --reporter=text ./node_modules/.bin/mocha --exit", + "test": "APP_ENV=test TEST_ENV=unit nyc --reporter=text ./node_modules/.bin/mocha --exit", + "test:integration": "APP_ENV=test TEST_ENV=integration nyc --reporter=text ./node_modules/.bin/mocha --exit", "lint": "eslint src/**/*.js", "docs": "./node_modules/.bin/apidoc -i src/ -o docs", "coverage": "nyc report --reporter=text-lcov | coveralls", diff --git a/src/modules/iredmail/controller.js b/src/modules/iredmail/controller.js new file mode 100644 index 0000000..a2f8492 --- /dev/null +++ b/src/modules/iredmail/controller.js @@ -0,0 +1,42 @@ +// const User = require('../../models/users') + +/* + Create a new user by manipulating the postgres database. +*/ +async function createUser (ctx) { + try { + // Sync the model. + await ctx.iRedMail.models.usedQuota.sync() + + // Get all the models in the database: + const models = await ctx.iRedMail.usedQuota.findAll() + + console.log(`data: ${JSON.stringify(models, null, 2)}`) + ctx.body = { models } + } catch (err) { + console.log(`Error in iredmail.createUser(): `, err) + ctx.throw(500, err.message) + } +/* + const user = new User(ctx.request.body.user) + try { + await user.save() + } catch (err) { + ctx.throw(422, err.message) + } + + const token = user.generateToken() + const response = user.toJSON() + + delete response.password + + ctx.body = { + user: response, + token + } + */ +} + +module.exports = { + createUser +} diff --git a/src/modules/iredmail/router.js b/src/modules/iredmail/router.js new file mode 100644 index 0000000..66d67df --- /dev/null +++ b/src/modules/iredmail/router.js @@ -0,0 +1,14 @@ +// const ensureUser = require('../../middleware/validators') +const iredmail = require('./controller') + +module.exports.baseUrl = '/iredmail' + +module.exports.routes = [ + { + method: 'POST', + route: '/adduser', + handlers: [ + iredmail.createUser + ] + } +] diff --git a/test/a03-iredmail.spec.js b/test/a03-iredmail.spec.js new file mode 100644 index 0000000..03ccdda --- /dev/null +++ b/test/a03-iredmail.spec.js @@ -0,0 +1,52 @@ +/* +*/ + +'use strict' + +const rp = require('request-promise') +const assert = require('chai').assert + +const IRedMail = require('../bin/iredmail') + +const util = require('util') +util.inspect.defaultOptions = { depth: 1 } + +const LOCALHOST = 'http://localhost:5000' + +describe('#iRedMail', () => { + let testType = 'unit' + let iRedMail + + before(async () => { + // Detect integration test flag. + if (process.env.TEST_ENV === 'integration') { + testType = 'integration' + + iRedMail = new IRedMail() + await iRedMail.sequelize.authenticate() + } + }) + + describe('#createUser', () => { + it('should get database models', async () => { + try { + console.log(`Hello world!`) + /* + const options = { + method: 'POST', + uri: `${LOCALHOST}/iredmail/adduser`, + resolveWithFullResponse: true, + json: true, + body: { + } + } + + let result = await rp(options) + console.log(`result: ${util.inspect(result)}`) + */ + } catch (err) { + console.log(`Error in #createUser test: `, err) + } + }) + }) +}) From 3063d7abdc066a7ef0fca2be043e994761a9ca3f Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 21 Jan 2019 18:33:27 -0800 Subject: [PATCH 2/8] getting data from postgres successfully --- bin/server.js | 18 +++++++------ package.json | 2 +- src/modules/iredmail/controller.js | 13 +++++++-- test/a03-iredmail.spec.js | 43 +++++++++++++++--------------- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/bin/server.js b/bin/server.js index 1b47ef2..b7e73df 100644 --- a/bin/server.js +++ b/bin/server.js @@ -54,15 +54,17 @@ async function startServer () { await app.listen(config.port) console.log(`Server started on ${config.port}`) - try { - const iRedMail = new IRedMail() - await iRedMail.sequelize.authenticate() - console.log('Connection to the iRedMail postgres database has been established successfully.') + if (process.env.TEST_ENV !== 'unit') { + try { + const iRedMail = new IRedMail() + await iRedMail.sequelize.authenticate() + console.log('Connection to the iRedMail postgres database has been established successfully.') - // Attach to iRedMail instantiation to the context object. - app.context.iRedMail = iRedMail - } catch (err) { - console.log(`Could not connect to iRedMail instance.`) + // Attach to iRedMail instantiation to the context object. + app.context.iRedMail = iRedMail + } catch (err) { + console.log(`Could not connect to iRedMail instance.`) + } } return app diff --git a/package.json b/package.json index 7f72bed..b4fed41 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "start": "node index.js", "test": "APP_ENV=test TEST_ENV=unit nyc --reporter=text ./node_modules/.bin/mocha --exit", - "test:integration": "APP_ENV=test TEST_ENV=integration nyc --reporter=text ./node_modules/.bin/mocha --exit", + "test:integration": "APP_ENV=test TEST_ENV=integration nyc --reporter=text ./node_modules/.bin/mocha --timeout 15000 --exit", "lint": "eslint src/**/*.js", "docs": "./node_modules/.bin/apidoc -i src/ -o docs", "coverage": "nyc report --reporter=text-lcov | coveralls", diff --git a/src/modules/iredmail/controller.js b/src/modules/iredmail/controller.js index a2f8492..c427331 100644 --- a/src/modules/iredmail/controller.js +++ b/src/modules/iredmail/controller.js @@ -1,18 +1,27 @@ // const User = require('../../models/users') +const util = require('util') +util.inspect.defaultOptions = { depth: 1 } + /* Create a new user by manipulating the postgres database. */ async function createUser (ctx) { try { - // Sync the model. - await ctx.iRedMail.models.usedQuota.sync() + // console.log(`ctx.iRedMail: ${util.inspect(ctx.iRedMail)}`) + // Sync the model. + const model = await ctx.iRedMail.models.usedQuota.sync() + + const data = await model.findAll() + /* // Get all the models in the database: const models = await ctx.iRedMail.usedQuota.findAll() console.log(`data: ${JSON.stringify(models, null, 2)}`) ctx.body = { models } + */ + ctx.body = data } catch (err) { console.log(`Error in iredmail.createUser(): `, err) ctx.throw(500, err.message) diff --git a/test/a03-iredmail.spec.js b/test/a03-iredmail.spec.js index 03ccdda..d784f70 100644 --- a/test/a03-iredmail.spec.js +++ b/test/a03-iredmail.spec.js @@ -22,31 +22,32 @@ describe('#iRedMail', () => { if (process.env.TEST_ENV === 'integration') { testType = 'integration' - iRedMail = new IRedMail() - await iRedMail.sequelize.authenticate() + // iRedMail = new IRedMail() + // await iRedMail.sequelize.authenticate() } }) describe('#createUser', () => { - it('should get database models', async () => { - try { - console.log(`Hello world!`) - /* - const options = { - method: 'POST', - uri: `${LOCALHOST}/iredmail/adduser`, - resolveWithFullResponse: true, - json: true, - body: { - } - } + if (process.env.TEST_ENV === 'integration') { + it('should get database models', async () => { + try { + // console.log(`Hello world!`) - let result = await rp(options) - console.log(`result: ${util.inspect(result)}`) - */ - } catch (err) { - console.log(`Error in #createUser test: `, err) - } - }) + const options = { + method: 'POST', + uri: `${LOCALHOST}/iredmail/adduser`, + resolveWithFullResponse: true, + json: true, + body: { + } + } + + let result = await rp(options) + console.log(`result: ${util.inspect(result.body)}`) + } catch (err) { + console.log(`Error in #createUser test: `, err) + } + }) + } }) }) From 91e559cd38a6ee03f169a3883bda5b464cee6b32 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 21 Jan 2019 18:37:39 -0800 Subject: [PATCH 3/8] Added integration test for getUsers --- src/modules/iredmail/controller.js | 15 +++++++-------- src/modules/iredmail/router.js | 7 +++++++ test/a03-iredmail.spec.js | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/modules/iredmail/controller.js b/src/modules/iredmail/controller.js index c427331..9948b1c 100644 --- a/src/modules/iredmail/controller.js +++ b/src/modules/iredmail/controller.js @@ -3,10 +3,14 @@ const util = require('util') util.inspect.defaultOptions = { depth: 1 } +async function createUser (ctx) { + ctx.body = {} +} + /* Create a new user by manipulating the postgres database. */ -async function createUser (ctx) { +async function getUsers (ctx) { try { // console.log(`ctx.iRedMail: ${util.inspect(ctx.iRedMail)}`) @@ -14,13 +18,7 @@ async function createUser (ctx) { const model = await ctx.iRedMail.models.usedQuota.sync() const data = await model.findAll() - /* - // Get all the models in the database: - const models = await ctx.iRedMail.usedQuota.findAll() - console.log(`data: ${JSON.stringify(models, null, 2)}`) - ctx.body = { models } - */ ctx.body = data } catch (err) { console.log(`Error in iredmail.createUser(): `, err) @@ -47,5 +45,6 @@ async function createUser (ctx) { } module.exports = { - createUser + createUser, + getUsers } diff --git a/src/modules/iredmail/router.js b/src/modules/iredmail/router.js index 66d67df..63ff9a9 100644 --- a/src/modules/iredmail/router.js +++ b/src/modules/iredmail/router.js @@ -10,5 +10,12 @@ module.exports.routes = [ handlers: [ iredmail.createUser ] + }, + { + method: 'GET', + route: '/', + handlers: [ + iredmail.getUsers + ] } ] diff --git a/test/a03-iredmail.spec.js b/test/a03-iredmail.spec.js index d784f70..bee1dd3 100644 --- a/test/a03-iredmail.spec.js +++ b/test/a03-iredmail.spec.js @@ -50,4 +50,26 @@ describe('#iRedMail', () => { }) } }) + + describe('#getUsers', () => { + if (process.env.TEST_ENV === 'integration') { + it('should get database models', async () => { + try { + // console.log(`Hello world!`) + + const options = { + method: 'GET', + uri: `${LOCALHOST}/iredmail`, + resolveWithFullResponse: true, + json: true + } + + let result = await rp(options) + console.log(`result: ${util.inspect(result.body)}`) + } catch (err) { + console.log(`Error in #createUser test: `, err) + } + }) + } + }) }) From ef993b276381e74329a59edcedd4a82c4ce1232a Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 22 Jan 2019 10:28:42 -0800 Subject: [PATCH 4/8] Adding mailbox model --- postgres/models/mailbox.js | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 postgres/models/mailbox.js diff --git a/postgres/models/mailbox.js b/postgres/models/mailbox.js new file mode 100644 index 0000000..1453b4a --- /dev/null +++ b/postgres/models/mailbox.js @@ -0,0 +1,75 @@ +/* + mailbox table in the iRedMail postgres database. + + The constructor cxpects an instantiation of the sequalize class. Returns a + Sequelize model. +*/ + +'use strict' + +const Sequelize = require('sequelize') + +class Mailbox { + // Expects an instantiation of the sequalize class. Returns a Sequelize model. + constructor (sequelize) { + return sequelize.define( + 'mailbox', + { + username: { type: Sequelize.STRING, primaryKey: true }, + password: Sequelize.STRING, + name: Sequelize.STRING, + language: Sequelize.STRING, + storagebasedirectory: Sequelize.STRING, + storagenode: Sequelize.STRING, + maildir: Sequelize.STRING, + quota: Sequelize.BIGINT, + domain: Sequelize.STRING, + transport: Sequelize.STRING, + department: Sequelize.STRING, + rank: Sequelize.STRING, + employeeid: Sequelize.STRING, + isadmin: Sequelize.INTEGER, + isglobaladmin: Sequelize.INTEGER, + enablesmtp: Sequelize.INTEGER, + enablesmtpsecured: Sequelize.INTEGER, + enableimaptls: Sequelize.INTEGER, + enabledeliver: Sequelize.INTEGER, + enablelda: Sequelize.INTEGER, + enablemanagesieve: Sequelize.INTEGER, + enablemanagesievesecured: Sequelize.INTEGER, + enablesieve: Sequelize.INTEGER, + enablesievesecured: Sequelize.INTEGER, + enablesievetls: Sequelize.INTEGER, + enableinternal: Sequelize.INTEGER, + enabledoveadm: Sequelize.INTEGER, + 'enablelib-storage': Sequelize.INTEGER, + 'enableindexer-worker': Sequelize.INTEGER, + enablelmtp: Sequelize.INTEGER, + enabledsync: Sequelize.INTEGER, + enablesogo: Sequelize.INTEGER, + allow_nets: Sequelize.STRING, + lastlogindate: Sequelize.DATE, + lastloginipv4: Sequelize.INET, + lastloginprotocol: Sequelize.STRING, + disclaimer: Sequelize.STRING, + allowedsenders: Sequelize.STRING, + rejectedsenders: Sequelize.STRING, + allowedrecipients: Sequelize.STRING, + rejectedrecipients: Sequelize.STRING, + settings: Sequelize.STRING, + passwordlastchange: Sequelize.DATE, + created: Sequelize.DATE, + modified: Sequelize.DATE, + expired: Sequelize.DATE, + active: Sequelize.INTEGER, + bytes: Sequelize.BIGINT, + messages: Sequelize.BIGINT + }, + { + timestamps: false + } + ) + } +} + +module.exports = Mailbox From 02fde0e300ac96a4a88421bf6913f1eb2b605c41 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 22 Jan 2019 15:26:50 -0800 Subject: [PATCH 5/8] Getting mailbox table --- bin/iredmail.js | 4 +++- postgres/models/mailbox.js | 13 +++++++++---- src/modules/iredmail/controller.js | 3 ++- test/a03-iredmail.spec.js | 1 - 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/iredmail.js b/bin/iredmail.js index ccca338..4a1567a 100644 --- a/bin/iredmail.js +++ b/bin/iredmail.js @@ -10,6 +10,7 @@ const config = require('../config') // Models const UsedQuota = require('../postgres/models/used-quota') +const Mailbox = require('../postgres/models/mailbox') class IRedMail { constructor () { @@ -18,7 +19,8 @@ class IRedMail { // Load the models this.models = { - usedQuota: new UsedQuota(this.sequelize) + usedQuota: new UsedQuota(this.sequelize), + mailbox: new Mailbox(this.sequelize) } } diff --git a/postgres/models/mailbox.js b/postgres/models/mailbox.js index 1453b4a..a5f4e9d 100644 --- a/postgres/models/mailbox.js +++ b/postgres/models/mailbox.js @@ -61,13 +61,18 @@ class Mailbox { created: Sequelize.DATE, modified: Sequelize.DATE, expired: Sequelize.DATE, - active: Sequelize.INTEGER, - bytes: Sequelize.BIGINT, - messages: Sequelize.BIGINT + active: Sequelize.INTEGER }, { - timestamps: false + timestamps: false, + // disable the modification of tablenames; By default, sequelize will automatically + // transform all passed model names (first parameter of define) into plural. + // if you don't want that, set the following + freezeTableName: true, + // define the table's name + tableName: 'mailbox' } + ) } } diff --git a/src/modules/iredmail/controller.js b/src/modules/iredmail/controller.js index 9948b1c..4e89008 100644 --- a/src/modules/iredmail/controller.js +++ b/src/modules/iredmail/controller.js @@ -15,7 +15,8 @@ async function getUsers (ctx) { // console.log(`ctx.iRedMail: ${util.inspect(ctx.iRedMail)}`) // Sync the model. - const model = await ctx.iRedMail.models.usedQuota.sync() + // const model = await ctx.iRedMail.models.usedQuota.sync() + const model = await ctx.iRedMail.models.mailbox.sync() const data = await model.findAll() diff --git a/test/a03-iredmail.spec.js b/test/a03-iredmail.spec.js index bee1dd3..a578fa4 100644 --- a/test/a03-iredmail.spec.js +++ b/test/a03-iredmail.spec.js @@ -15,7 +15,6 @@ const LOCALHOST = 'http://localhost:5000' describe('#iRedMail', () => { let testType = 'unit' - let iRedMail before(async () => { // Detect integration test flag. From 49002dc1056486726a0fd28f4f5aaa87f47ca6a8 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 22 Jan 2019 16:43:59 -0800 Subject: [PATCH 6/8] got forwardings table --- bin/iredmail.js | 4 ++- postgres/models/forwardings.js | 42 ++++++++++++++++++++++++++++++ src/modules/iredmail/controller.js | 3 ++- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 postgres/models/forwardings.js diff --git a/bin/iredmail.js b/bin/iredmail.js index 4a1567a..8c0d9b0 100644 --- a/bin/iredmail.js +++ b/bin/iredmail.js @@ -11,6 +11,7 @@ const config = require('../config') // Models const UsedQuota = require('../postgres/models/used-quota') const Mailbox = require('../postgres/models/mailbox') +const Forwardings = require('../postgres/models/forwardings') class IRedMail { constructor () { @@ -20,7 +21,8 @@ class IRedMail { // Load the models this.models = { usedQuota: new UsedQuota(this.sequelize), - mailbox: new Mailbox(this.sequelize) + mailbox: new Mailbox(this.sequelize), + forwardings: new Forwardings(this.sequelize) } } diff --git a/postgres/models/forwardings.js b/postgres/models/forwardings.js new file mode 100644 index 0000000..e33a8ed --- /dev/null +++ b/postgres/models/forwardings.js @@ -0,0 +1,42 @@ +/* + Forwardings table in the iRedMail postgres database. + + The constructor cxpects an instantiation of the sequalize class. Returns a + Sequelize model. +*/ + +'use strict' + +const Sequelize = require('sequelize') + +class Forwardings { + // Expects an instantiation of the sequalize class. Returns a Sequelize model. + constructor (sequelize) { + return sequelize.define( + 'forwardings', + { + id: { type: Sequelize.INTEGER, primaryKey: true }, + address: Sequelize.STRING, + forwarding: Sequelize.STRING, + domain: Sequelize.STRING, + dest_domain: Sequelize.STRING, + is_maillist: Sequelize.INTEGER, + is_list: Sequelize.INTEGER, + is_forwarding: Sequelize.INTEGER, + is_alias: Sequelize.INTEGER, + active: Sequelize.INTEGER + }, + { + timestamps: false, + // disable the modification of tablenames; By default, sequelize will automatically + // transform all passed model names (first parameter of define) into plural. + // if you don't want that, set the following + freezeTableName: true, + // define the table's name + tableName: 'forwardings' + } + ) + } +} + +module.exports = Forwardings diff --git a/src/modules/iredmail/controller.js b/src/modules/iredmail/controller.js index 4e89008..d48f2b0 100644 --- a/src/modules/iredmail/controller.js +++ b/src/modules/iredmail/controller.js @@ -16,7 +16,8 @@ async function getUsers (ctx) { // Sync the model. // const model = await ctx.iRedMail.models.usedQuota.sync() - const model = await ctx.iRedMail.models.mailbox.sync() + // const model = await ctx.iRedMail.models.mailbox.sync() + const model = await ctx.iRedMail.models.forwardings.sync() const data = await model.findAll() From 87cb1fc815731648b1d2fdffa41eef8c1a40207d Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 22 Jan 2019 16:53:07 -0800 Subject: [PATCH 7/8] getUsers returns usernames --- src/modules/iredmail/controller.js | 12 +++++++----- test/a03-iredmail.spec.js | 8 ++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/modules/iredmail/controller.js b/src/modules/iredmail/controller.js index d48f2b0..a39aef0 100644 --- a/src/modules/iredmail/controller.js +++ b/src/modules/iredmail/controller.js @@ -12,16 +12,18 @@ async function createUser (ctx) { */ async function getUsers (ctx) { try { - // console.log(`ctx.iRedMail: ${util.inspect(ctx.iRedMail)}`) - // Sync the model. // const model = await ctx.iRedMail.models.usedQuota.sync() - // const model = await ctx.iRedMail.models.mailbox.sync() - const model = await ctx.iRedMail.models.forwardings.sync() + const model = await ctx.iRedMail.models.mailbox.sync() + // const model = await ctx.iRedMail.models.forwardings.sync() + // Get every model in the database. const data = await model.findAll() - ctx.body = data + // Get just the user name. + const users = data.map(x => x.username) + + ctx.body = users } catch (err) { console.log(`Error in iredmail.createUser(): `, err) ctx.throw(500, err.message) diff --git a/test/a03-iredmail.spec.js b/test/a03-iredmail.spec.js index a578fa4..1cc0a09 100644 --- a/test/a03-iredmail.spec.js +++ b/test/a03-iredmail.spec.js @@ -52,7 +52,7 @@ describe('#iRedMail', () => { describe('#getUsers', () => { if (process.env.TEST_ENV === 'integration') { - it('should get database models', async () => { + it('should get usernames of all users in mailbox table', async () => { try { // console.log(`Hello world!`) @@ -64,7 +64,11 @@ describe('#iRedMail', () => { } let result = await rp(options) - console.log(`result: ${util.inspect(result.body)}`) + // console.log(`result: ${util.inspect(result.body)}`) + + // Returns an array of username/email strings. + assert.isArray(result.body) + assert.isString(result.body[0]) } catch (err) { console.log(`Error in #createUser test: `, err) } From 77d25ef7829d812f476e9cff657c26fee4652b0d Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 6 Feb 2019 20:58:49 -0800 Subject: [PATCH 8/8] Started to flesh in the createUser() function --- postgres/models/mailbox.js | 2 +- src/modules/iredmail/controller.js | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/postgres/models/mailbox.js b/postgres/models/mailbox.js index a5f4e9d..2cc82eb 100644 --- a/postgres/models/mailbox.js +++ b/postgres/models/mailbox.js @@ -1,7 +1,7 @@ /* mailbox table in the iRedMail postgres database. - The constructor cxpects an instantiation of the sequalize class. Returns a + The constructor expects an instantiation of the sequalize class. Returns a Sequelize model. */ diff --git a/src/modules/iredmail/controller.js b/src/modules/iredmail/controller.js index a39aef0..a765b1c 100644 --- a/src/modules/iredmail/controller.js +++ b/src/modules/iredmail/controller.js @@ -4,7 +4,18 @@ const util = require('util') util.inspect.defaultOptions = { depth: 1 } async function createUser (ctx) { - ctx.body = {} + try { + const modelMailbox = await ctx.iRedMail.models.mailbox.sync() + const modelForwardings = await ctx.iRedMail.models.forwardings.sync() + + // http://docs.sequelizejs.com/ + // await modelMailbox.create({}) + + ctx.body = {} + } catch (err) { + console.log(`Error in iredmail.createUser(): `, err) + ctx.throw(500, err.message) + } } /* @@ -25,10 +36,10 @@ async function getUsers (ctx) { ctx.body = users } catch (err) { - console.log(`Error in iredmail.createUser(): `, err) + console.log(`Error in iredmail.getUsers(): `, err) ctx.throw(500, err.message) } -/* + /* const user = new User(ctx.request.body.user) try { await user.save()