1234567891011121314151617181920212223242526272829303132333435 |
- '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 LevelService extends CrudService {
- constructor(ctx) {
- super(ctx, 'news');
- this.model = this.ctx.model.Level;
- this.dmodel = this.ctx.model.Department;
- }
- async query({ skip, limit, ...info }) {
- const total = await (await this.model.find(info)).length;
- const levels = await this.model
- .find(info)
- .skip(Number(skip))
- .limit(Number(limit));
- const newdatas = [];
- for (let level of levels) {
- level = JSON.parse(JSON.stringify(level));
- const dept = await this.dmodel.findById(level.dept_id);
- level.dept_name = dept.name;
- newdatas.push(level);
- }
- return { data: newdatas, total };
- }
- }
- module.exports = LevelService;
|