refactor(api): update story query helper
it now filters out stories with nonexistent authors
This commit is contained in:
parent
5a3516e05b
commit
fea42915fb
@ -2,7 +2,7 @@ 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"
|
||||||
|
|
||||||
export default async function(query, context, limit?, 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 = {}
|
||||||
@ -19,5 +19,5 @@ export default async function(query, context, limit?, sort?) {
|
|||||||
.populate({path: "challenge", model: Challenge}).populate('author', 'username _id')
|
.populate({path: "challenge", model: Challenge}).populate('author', 'username _id')
|
||||||
.limit(limit || Infinity)
|
.limit(limit || Infinity)
|
||||||
.exec();
|
.exec();
|
||||||
return stories
|
return stories.filter(a => a.author != null)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user