From 49002dc1056486726a0fd28f4f5aaa87f47ca6a8 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 22 Jan 2019 16:43:59 -0800 Subject: [PATCH] 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()