student.js 1009 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. // 学生视图接口
  7. class StudentService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'lessonprivate');
  10. this.lessonModel = this.ctx.model.Business.Lesson;
  11. this.lessonStudentModel = this.ctx.model.Business.LessonStudent;
  12. }
  13. async lessonList({ student_id, school_id, skip = 0, limit = 0, ...otherQuery }) {
  14. // 查出该学生的课表
  15. const lsList = await this.lessonStudentModel.find({ student_id, school_id }, { lesson_id: 1 });
  16. const lessonIds = lsList.map(i => i.lesson_id);
  17. const data = await this.lessonModel.find({ _id: lessonIds, ...otherQuery }).skip(parseInt(skip)).limit(parseInt(limit));
  18. const total = await this.lessonModel.count({ _id: lessonIds, ...otherQuery });
  19. return { data, total };
  20. }
  21. }
  22. module.exports = StudentService;