summaryrefslogtreecommitdiff
path: root/bucky/db/index.js
diff options
context:
space:
mode:
authorjulian laplace <julescarbon@gmail.com>2022-10-26 17:05:14 +0200
committerjulian laplace <julescarbon@gmail.com>2022-10-26 17:05:14 +0200
commitdd72ab05da17309fd5ee6005cdc1fae686b5fa9e (patch)
tree9edc695fffa73a85d94e571f44c7d4c97de71654 /bucky/db/index.js
parent3de2a5872fd0481568e918a1ea798b3f75ace610 (diff)
filter by keyword, thread, or username
Diffstat (limited to 'bucky/db/index.js')
-rw-r--r--bucky/db/index.js30
1 files changed, 26 insertions, 4 deletions
diff --git a/bucky/db/index.js b/bucky/db/index.js
index 36541f8..2a1a3bf 100644
--- a/bucky/db/index.js
+++ b/bucky/db/index.js
@@ -116,19 +116,41 @@ db.getLastlog = function (limit) {
/** HOOTSTREAM */
-db.getHootstreamFiles = ({ limit, offset }) =>
+db.getHootstreamFiles = ({ limit, offset, thread, keyword, username }) =>
knex("files")
.join("threads", "threads.id", "=", "files.thread")
.select("files.*")
- .where("threads.privacy", false)
+ .where((builder) => {
+ builder.where("threads.privacy", false);
+ if (keyword) {
+ builder.where("threads.keyword", keyword);
+ }
+ if (thread) {
+ builder.where("threads.id", thread);
+ }
+ if (username) {
+ builder.where("comments.username", username);
+ }
+ })
.orderBy("files.id", "desc")
.offset(offset)
.limit(limit);
-db.getHootstreamComments = ({ limit, offset }) =>
+db.getHootstreamComments = ({ limit, offset, thread, keyword, username }) =>
knex("comments")
.join("threads", "threads.id", "=", "comments.thread")
.select("comments.*")
- .where("threads.privacy", false)
+ .where((builder) => {
+ builder.where("threads.privacy", false);
+ if (keyword) {
+ builder.where("threads.keyword", keyword);
+ }
+ if (thread) {
+ builder.where("threads.id", thread);
+ }
+ if (username) {
+ builder.where("comments.username", username);
+ }
+ })
.orderBy("comments.id", "desc")
.offset(offset)
.limit(limit);