diff --git a/lib/functions.ts b/lib/functions.ts index 42f436a..5298d2b 100644 --- a/lib/functions.ts +++ b/lib/functions.ts @@ -6,6 +6,7 @@ import { GridFSBucketReadStream } from "mongodb"; import { stripHtml } from "string-strip-html"; import { IStory } from "~/models/stories"; import { ficsHidden } from "./server/ficmas"; +import { PreMiddlewareFunction, Query } from "mongoose"; // const { encode, decode } = iconv; @@ -13,15 +14,22 @@ export function countWords(string: string) { return stripHtml(string).result.split(/W+/).length; } -export function populate(field: string) { +export function populate( + field: string, + model: string, +): PreMiddlewareFunction> { return function (next: () => any) { - this.populate(field); + this.populate(field, undefined, model); next(); }; } -export function populateSelected(field: string, selection: string) { +export function populateSelected( + field: string, + model: string, + selection: string, +): PreMiddlewareFunction> { return function (next: () => any) { - this.populate(field, selection); + this.populate(field, selection, model); next(); }; }