liuyu 4 年之前
父节点
当前提交
659f76a46b
共有 1 个文件被更改,包括 10 次插入5 次删除
  1. 10 5
      app/service/group.js

+ 10 - 5
app/service/group.js

@@ -89,12 +89,17 @@ class GroupService extends CrudService {
     const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
     const data = [];
     for (const _group of res) {
-      const group = _.cloneDeep(JSON.parse(JSON.stringify(_group)));
-      for (const stu of group.students) {
-        const student = await this.smodel.findOne({ id: stu.stuid });
-        if (student) stu.job = student.job;
+      const stus = [];
+      for (const stu of _group.students) {
+        const student = await this.smodel.findById(stu.stuid);
+        let job = '';
+        if (student) {
+          job = student.job;
+        }
+        stus.push({ ...JSON.parse(JSON.stringify(stu)), job });
       }
-      data.push(group);
+      _group.students = stus;
+      data.push(_group);
     }
     return { total, data };
   }