student.js 1.1 KB

123456789101112131415161718192021222324252627
  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 query = {};
  16. if (student_id)query.student_id = student_id;
  17. if (school_id) query.school_id = school_id;
  18. const lsList = await this.lessonStudentModel.find(query, { lesson_id: 1 });
  19. const lessonIds = lsList.map(i => i.lesson_id);
  20. const data = await this.lessonModel.find({ _id: lessonIds, ...otherQuery }).skip(parseInt(skip)).limit(parseInt(limit));
  21. const total = await this.lessonModel.count({ _id: lessonIds, ...otherQuery });
  22. return { data, total };
  23. }
  24. }
  25. module.exports = StudentService;