refactor(api): update story query helper

it now filters out stories with nonexistent authors
This commit is contained in:
parent 5a3516e05b
commit fea42915fb
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

@ -2,7 +2,7 @@ import { Band } from "~/models/band"
import { Challenge } from "~/models/challenges/gen"
import { Story } from "~/models/stories"
export default async function(query, context, limit?, sort?) {
export default async function(query, context, limit?: number, sort?) {
query["chapters.hidden"] = false
if(context.currentUser) {
if(!query.author) query.author = {}
@ -19,5 +19,5 @@ export default async function(query, context, limit?, sort?) {
.populate({path: "challenge", model: Challenge}).populate('author', 'username _id')
.limit(limit || Infinity)
.exec();
return stories
return stories.filter(a => a.author != null)
}