apply.js 982 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 ApplyService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'apply');
  10. this.model = this.ctx.model.Apply;
  11. this.tmodel = this.ctx.model.Teacher;
  12. }
  13. // 查询
  14. async query({ skip, limit, ...num }) {
  15. const total = await this.model.find(num).length;
  16. const data = await this.model.find(num).skip(Number(skip)).limit(Number(limit));
  17. console.log(data);
  18. const teachers = [];
  19. for (const _data of data) {
  20. const teacherid = _data.teacherid;
  21. const teacher = await this.tmodel.findById(teacherid);
  22. teachers.push(teacher);
  23. }
  24. const newdata = { data, teachers };
  25. const result = { total, newdata };
  26. return result;
  27. }
  28. }
  29. module.exports = ApplyService;