Newest.ts 713 B

12345678910111213141516171819202122232425
  1. import Joi from "joi";
  2. import DataModule from "@/modules/DataModule";
  3. import DataModuleJob from "@/modules/DataModule/DataModuleJob";
  4. import { NewsModel } from "../schema";
  5. export default class Newest extends DataModuleJob {
  6. protected static _modelName = "news";
  7. protected static _hasPermission = true;
  8. protected static _payloadSchema = Joi.object({
  9. showToNewUsers: Joi.boolean().optional(),
  10. limit: Joi.number().min(1).optional()
  11. });
  12. protected async _execute() {
  13. const model = await DataModule.getModel<NewsModel>(this.getModelName());
  14. const query = model.find().newest(this._payload?.showToNewUsers);
  15. if (this._payload?.limit) return query.limit(this._payload?.limit);
  16. return query;
  17. }
  18. }