2023-09-25 19:31:30 -04:00
|
|
|
import { Band } from "~/models/band"
|
|
|
|
import { Challenge } from "~/models/challenges/gen"
|
|
|
|
import { Story } from "~/models/stories"
|
|
|
|
|
2023-09-26 14:23:11 -04:00
|
|
|
export default async function(query, context, limit?: number, sort?) {
|
2023-09-25 19:31:30 -04:00
|
|
|
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();
|
2023-09-26 14:23:11 -04:00
|
|
|
return stories.filter(a => a.author != null)
|
2023-09-25 19:31:30 -04:00
|
|
|
}
|