viewnews.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class ViewnewsService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'viewnews');
  10. this.model = this.ctx.model.Viewnews;
  11. }
  12. async insertViewNews(title,news,qyid){
  13. const newdata={};
  14. newdata.title = title;
  15. newdata.news = news;
  16. newdata.qyid = qyid;
  17. newdata.status = '0';
  18. const res = await this.model.create(newdata);
  19. return res;
  20. }
  21. async getSelect(data){
  22. const match = {};
  23. match.qyid =data.qyid;
  24. const skip = Number.parseInt(data.skip) || 1;
  25. const limit = Number.parseInt(data.limit) || 10;
  26. const total = await this.model.count(match);
  27. const res = await this.model.find(match).sort({'meta.createdAt':-1}).limit(limit).skip((skip - 1) * limit);
  28. const newres = {res,total};
  29. return newres;
  30. }
  31. }
  32. module.exports = ViewnewsService;