refactor(server/utils): move listQuerier to separate database helper folder

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-10-03 00:30:22 -04:00
parent 09187fa5ac
commit c9574dfc29
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
2 changed files with 30 additions and 23 deletions

View File

@ -0,0 +1,30 @@
import { Band } from "~/models/band";
import { Challenge } from "~/models/challenges/gen";
import { Story } from "~/models/stories";
export default async function (query, context, limit?: number, sort?) {
query["chapters.hidden"] = false;
if (context.currentUser) {
if (!query.author) query.author = {};
if (!query["chapters.bands"]) query["chapters.bands"] = {};
query["chapters.bands"]["$nin"] = context.currentUser.hidden_bands;
query["author"]["$nin"] = context.currentUser.hidden_authors;
}
query["ficmas"] = {
$nin: context.ficmasarray_raw.map((a) => a._id),
};
console.log(query);
let stories = await Story.find(query, null)
.collation({ locale: "en" })
.sort(sort ? sort : { "chapters.posted": -1 })
.populate({
path: "ficmas",
populate: { path: "wisher", model: "User", select: "username _id" },
})
.populate("chapters.bands")
.populate({ path: "challenge", model: Challenge })
.populate("author", "username _id")
.limit(limit || Infinity)
.exec();
return stories.filter((a) => a.author != null);
}

View File

@ -1,23 +0,0 @@
import { Band } from "~/models/band"
import { Challenge } from "~/models/challenges/gen"
import { Story } from "~/models/stories"
export default async function(query, context, limit?: number, sort?) {
query["chapters.hidden"] = false
if(context.currentUser) {
if(!query.author) query.author = {}
if(!query["chapters.bands"]) query["chapters.bands"] = {}
query["chapters.bands"]["$nin"] = context.currentUser.hidden_bands
query["author"]["$nin"] = context.currentUser.hidden_authors
}
query["ficmas"] = {
"$nin": context.ficmasarray_raw.map(a => a._id)
};
console.log(query)
let stories = await Story.find(query, null).collation({locale: "en"}).sort(sort ? sort : {"chapters.posted": -1})
.populate({path: 'ficmas', populate: {path: 'wisher', model: 'User', select: 'username _id'}}).populate("chapters.bands")
.populate({path: "challenge", model: Challenge}).populate('author', 'username _id')
.limit(limit || Infinity)
.exec();
return stories.filter(a => a.author != null)
}