fix(api/utils): fix listquerier

make it so that `author` is an object we can assign to, NOT a number
This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-10-10 22:25:25 -04:00
parent b4e8894291
commit c502acbba9
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -1,19 +1,20 @@
import { Band } from "~/models/band"; import { Band } from "~/models/band";
import { Challenge } from "~/models/challenges/gen"; import { Challenge } from "~/models/challenges/gen";
import { Story } from "~/models/stories"; import { Story } from "~/models/stories";
import { log } from "../logger";
export default async function (query, context, limit?: number, sort?) { export default async function (query, context, limit?: number, sort?) {
query["chapters.hidden"] = false; query["chapters.hidden"] = false;
if (context.currentUser) { if (context.currentUser) {
if (!query.author) query.author = {}; if (!query.author) query.author = {};
if (!query["chapters.bands"]) query["chapters.bands"] = {}; if (!query["chapters.bands"]) query["chapters.bands"] = {};
query["chapters.bands"]["$nin"] = context.currentUser.hidden_bands; query["chapters.bands"]["$nin"] = context.currentUser.hiddenBands;
query["author"]["$nin"] = context.currentUser.hidden_authors; query["author"]["$nin"] = context.currentUser.hiddenAuthors;
} }
query["ficmas"] = { query["ficmas"] = {
$nin: context.ficmasarray_raw.map((a) => a._id), $nin: context.ficmasarray_raw.map((a) => a._id),
}; };
console.log(query); log.debug(query, { label: "list query" });
let stories = await Story.find(query, null) let stories = await Story.find(query, null)
.collation({ locale: "en" }) .collation({ locale: "en" })
.sort(sort ? sort : { "chapters.posted": -1 }) .sort(sort ? sort : { "chapters.posted": -1 })