level.js 965 B

1234567891011121314151617181920212223242526272829303132333435
  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 LevelService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'news');
  10. this.model = this.ctx.model.Level;
  11. this.dmodel = this.ctx.model.Department;
  12. }
  13. async query({ skip, limit, ...info }) {
  14. const total = await (await this.model.find(info)).length;
  15. const levels = await this.model
  16. .find(info)
  17. .skip(Number(skip))
  18. .limit(Number(limit));
  19. const newdatas = [];
  20. for (let level of levels) {
  21. level = JSON.parse(JSON.stringify(level));
  22. const dept = await this.dmodel.findById(level.dept_id);
  23. level.dept_name = dept.name;
  24. newdatas.push(level);
  25. }
  26. return { data: newdatas, total };
  27. }
  28. }
  29. module.exports = LevelService;