'use strict'; const assert = require('assert'); const _ = require('lodash'); const { ObjectId } = require('mongoose').Types; const { CrudService } = require('naf-framework-mongoose/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; class ViewnewsService extends CrudService { constructor(ctx) { super(ctx, 'viewnews'); this.model = this.ctx.model.Viewnews; } async insertViewNews(title,news,qyid){ const newdata={}; newdata.title = title; newdata.news = news; newdata.qyid = qyid; newdata.status = '0'; const res = await this.model.create(newdata); return res; } async getSelect(data){ const match = {}; match.qyid =data.qyid; const skip = Number.parseInt(data.skip) || 1; const limit = Number.parseInt(data.limit) || 10; const total = await this.model.count(match); const res = await this.model.find(match).sort({'meta.createdAt':-1}).limit(limit).skip((skip - 1) * limit); const newres = {res,total}; return newres; } } module.exports = ViewnewsService;