'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 ApplyService extends CrudService { constructor(ctx) { super(ctx, 'apply'); this.model = this.ctx.model.Apply; this.tmodel = this.ctx.model.Teacher; } // 查询 async query({ skip, limit, ...num }) { const total = await this.model.find(num).length; const data = await this.model.find(num).skip(Number(skip)).limit(Number(limit)); console.log(data); const teachers = []; for (const _data of data) { const teacherid = _data.teacherid; const teacher = await this.tmodel.findById(teacherid); teachers.push(teacher); } const newdata = { data, teachers }; const result = { total, newdata }; return result; } } module.exports = ApplyService;