mirror of
https://github.com/Permissionless-Software-Foundation/bch-email-api.git
synced 2026-09-21 16:52:04 -07:00
Added iredmail class and used-quota model
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
A class for connecting to and controlling the postgres database of an iredmail
|
||||
email server.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const Sequelize = require('sequelize')
|
||||
const config = require('../config')
|
||||
|
||||
// Models
|
||||
const UsedQuota = require('../postgres/models/used-quota')
|
||||
|
||||
class IRedMail {
|
||||
constructor () {
|
||||
// Instantiate and initialize sequelize.
|
||||
this.sequelize = this.initSequelize()
|
||||
|
||||
// Load the models
|
||||
this.models = {
|
||||
usedQuota: new UsedQuota(this.sequelize)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns an instance of the sequelize class, configured for the Postgres
|
||||
// database defined in the config object.
|
||||
initSequelize () {
|
||||
return new Sequelize('vmail', config.postgresUser, config.postgresPass, {
|
||||
host: config.postgresHost,
|
||||
dialect: 'postgres',
|
||||
|
||||
pool: {
|
||||
max: 5,
|
||||
min: 0,
|
||||
acquire: 30000,
|
||||
idle: 10000
|
||||
},
|
||||
|
||||
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
|
||||
operatorsAliases: false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = IRedMail
|
||||
+10
-29
@@ -8,7 +8,8 @@ const passport = require('koa-passport')
|
||||
const mount = require('koa-mount')
|
||||
const serve = require('koa-static')
|
||||
const cors = require('kcors')
|
||||
const Sequelize = require('sequelize')
|
||||
|
||||
const IRedMail = require('./iredmail')
|
||||
|
||||
const config = require('../config')
|
||||
const errorMiddleware = require('../src/middleware')
|
||||
@@ -53,41 +54,20 @@ async function startServer () {
|
||||
await app.listen(config.port)
|
||||
console.log(`Server started on ${config.port}`)
|
||||
|
||||
runTest()
|
||||
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
|
||||
|
||||
return app
|
||||
}
|
||||
// startServer()
|
||||
|
||||
/*
|
||||
async function runTest () {
|
||||
try {
|
||||
const sequelize = new Sequelize('vmail', config.postgresUser, config.postgresPass, {
|
||||
host: config.postgresHost,
|
||||
dialect: 'postgres',
|
||||
|
||||
pool: {
|
||||
max: 5,
|
||||
min: 0,
|
||||
acquire: 30000,
|
||||
idle: 10000
|
||||
},
|
||||
|
||||
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
|
||||
operatorsAliases: false
|
||||
})
|
||||
|
||||
const UsedQuota = sequelize.define(
|
||||
'used_quota',
|
||||
{
|
||||
username: { type: Sequelize.STRING, primaryKey: true },
|
||||
bytes: Sequelize.BIGINT,
|
||||
messages: Sequelize.BIGINT,
|
||||
domain: Sequelize.STRING
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
}
|
||||
)
|
||||
|
||||
await sequelize.authenticate()
|
||||
|
||||
@@ -102,6 +82,7 @@ async function runTest () {
|
||||
console.log(`Error: `, err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// export default app
|
||||
// module.exports = app
|
||||
|
||||
Reference in New Issue
Block a user