|
@@ -3,6 +3,7 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const _ = require('lodash');
|
|
|
const assert = require('assert');
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
|
|
|
// 学生视图接口
|
|
|
class StudentService extends CrudService {
|
|
@@ -16,9 +17,17 @@ class StudentService extends CrudService {
|
|
|
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 lsList = await this.lessonStudentModel.find(query, { lesson_id: 1, is_pay: 1, is_try: 1 });
|
|
|
+ console.log(lsList);
|
|
|
const lessonIds = lsList.map(i => i.lesson_id);
|
|
|
- const data = await this.lessonModel.find({ _id: lessonIds, ...otherQuery }).skip(parseInt(skip)).limit(parseInt(limit));
|
|
|
+ let data = await this.lessonModel.find({ _id: lessonIds, ...otherQuery }).skip(parseInt(skip)).limit(parseInt(limit));
|
|
|
+ if (data.length > 0) data = JSON.parse(JSON.stringify(data));
|
|
|
+ data = data.map(i => {
|
|
|
+ const { _id } = i;
|
|
|
+ const r = this.lsList.find(f => ObjectId(f).equals(_id));
|
|
|
+ if (r) i = { ...i, ..._.pick(r, [ 'is_try', 'is_pay' ]) };
|
|
|
+ return i;
|
|
|
+ });
|
|
|
const total = await this.lessonModel.count({ _id: lessonIds, ...otherQuery });
|
|
|
return { data, total };
|
|
|
}
|