From aefc83f729ab3f3c35d9371ec972fb6885b13125 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 12 Dec 2017 08:46:28 +0100 Subject: mail qa --- bucky/db/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'bucky/db/index.js') diff --git a/bucky/db/index.js b/bucky/db/index.js index c2cf947..8715125 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -51,8 +51,7 @@ db.getUser = function(id) { return model.fetch() } db.getUserByUsername = function(username) { - var model = new User({'username': username}) - return model.fetch() + return new User({'username': username}).fetch() } db.getLastlog = function(limit){ return knex.column('username').column('lastseen').select().from('users').orderBy('lastseen', 'desc').limit(limit || 10) @@ -188,12 +187,18 @@ db.destroyKeyword = function(id){ db.getMailboxes = function(username){ return Mailbox.query("where", "owner", "=", username).fetchAll() } +db.getMailbox = function(mbox){ + return new Mailbox({mbox: mbox}).fetch() +} db.getMailboxCounts = function(boxes){ return knex.column('mbox').count('* as count').select().from('messages').where('mbox', 'in', boxes).groupBy('mbox') } db.createMailbox = function(data){ return new db.Mailbox(data).save() } +db.bumpMailboxCount = function(mbox){ + new db.Mailbox({ mbox: mbox }).fetch() +} /* MESSAGES */ @@ -212,6 +217,7 @@ db.getMessages = function(username, box, limit, offset){ db.getMessage = function (id){ var model = new Message({'id': id}) return model.fetch().then(function(message){ + if (! message) return null message.set("body", message.get("body").toString() ) return message }) -- cgit v1.2.3-70-g09d2