123456789101112131415161718192021222324252627 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- // 学生视图接口
- class StudentService extends CrudService {
- constructor(ctx) {
- super(ctx, 'lessonprivate');
- this.lessonModel = this.ctx.model.Business.Lesson;
- this.lessonStudentModel = this.ctx.model.Business.LessonStudent;
- }
- async lessonList({ student_id, school_id, skip = 0, limit = 0, ...otherQuery }) {
- // 查出该学生的课表
- const query = {};
- if (student_id)query.student_id = student_id;
- if (school_id) query.school_id = school_id;
- const lsList = await this.lessonStudentModel.find(query, { lesson_id: 1 });
- const lessonIds = lsList.map(i => i.lesson_id);
- const data = await this.lessonModel.find({ _id: lessonIds, ...otherQuery }).skip(parseInt(skip)).limit(parseInt(limit));
- const total = await this.lessonModel.count({ _id: lessonIds, ...otherQuery });
- return { data, total };
- }
- }
- module.exports = StudentService;
|