|
@@ -8,6 +8,7 @@ import {
|
|
|
} from "mongoose";
|
|
|
import { GetData } from "./plugins/getData";
|
|
|
import { BaseSchema } from "../types/Schemas";
|
|
|
+import JobContext from "../JobContext";
|
|
|
|
|
|
export enum NewsStatus {
|
|
|
DRAFT = "draft",
|
|
@@ -52,7 +53,13 @@ export interface NewsQueryHelpers {
|
|
|
|
|
|
export interface NewsModel
|
|
|
extends Model<NewsSchema, NewsQueryHelpers>,
|
|
|
- GetData {}
|
|
|
+ GetData {
|
|
|
+ published: (context: JobContext) => Promise<NewsSchema[]>;
|
|
|
+ newest: (
|
|
|
+ context: JobContext,
|
|
|
+ payload: { showToNewUsers?: boolean }
|
|
|
+ ) => Promise<NewsSchema[]>;
|
|
|
+}
|
|
|
|
|
|
export const schema = new Schema<NewsSchema, NewsModel, {}, NewsQueryHelpers>(
|
|
|
{
|
|
@@ -93,6 +100,14 @@ export const schema = new Schema<NewsSchema, NewsModel, {}, NewsQueryHelpers>(
|
|
|
return query;
|
|
|
}
|
|
|
},
|
|
|
+ statics: {
|
|
|
+ published() {
|
|
|
+ return this.find().published();
|
|
|
+ },
|
|
|
+ newest(context: JobContext, payload: { showToNewUsers?: boolean }) {
|
|
|
+ return this.find().newest(payload.showToNewUsers);
|
|
|
+ }
|
|
|
+ },
|
|
|
// @ts-ignore need to somehow use GetDataSchemaOptions
|
|
|
getData: {
|
|
|
enabled: true,
|