mirror of
https://github.com/Permissionless-Software-Foundation/bch-email-api.git
synced 2026-09-21 16:52:04 -07:00
getUsers returns usernames
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user