From f8055775f3ac74e9e6054aef102673cefcf27986 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 25 Jan 2018 02:15:48 +0100 Subject: more on profile --- bucky/db/index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'bucky/db/index.js') diff --git a/bucky/db/index.js b/bucky/db/index.js index 935219f..a147cd8 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -93,6 +93,16 @@ db.getThreadsForKeyword = function (keyword) { qb.where("keyword", "=", keyword).orderBy("id", "desc") }).fetchAll() } +db.getThreadsForUser = function (username, limit, offset) { + return Thread.query(function(qb){ + qb.where("username", "=", username).orderBy("id", "desc").limit(limit || 40).offset(offset || 0) + }).fetchAll() +} +db.getTopThreadsForUser = function (username, limit, offset) { + return Thread.query(function(qb){ + qb.where("username", "=", username).orderBy("viewed", "desc").limit(limit || 40).offset(offset || 0) + }).fetchAll() +} db.getThread = function (id) { return Thread.query("where", "id", "=", id).fetch() } @@ -138,6 +148,14 @@ db.getFileById = function(id){ db.getFilesForThread = function (id){ return File.query("where", "thread", "=", id).fetchAll() } +db.getFilesForUser = function (username, limit, offset){ + return File.query(function(qb){ + qb.where("username", "=", username) + .orderBy('id', 'desc') + .limit(parseInt(limit) || 20) + .offset(parseInt(offset) || 0) + }).fetchAll() +} db.getFileCounts = function(ids){ return knex.column('thread').count('* as count').select().from('files').where('thread', 'in', ids).groupBy('thread') } @@ -225,6 +243,13 @@ db.getCommentById = function(id){ db.getCommentsById = function(ids){ return Comment.where("id", "in", ids).fetchAll() } +db.getCommentsForUser = function (username, limit){ + return Comment.query(function(qb){ + qb.where("username", "=", username) + .orderBy('date', 'desc') + .limit(parseInt(limit) || 20) + }).fetchAll() +} db.getCommentCounts = function(ids){ return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread') } -- cgit v1.2.3-70-g09d2