Browse Source

新增查询某期没有班级id的学生的接口

reloaded 5 years ago
parent
commit
d5b81faa6e
3 changed files with 16 additions and 1 deletions
  1. 7 1
      app/controller/student.js
  2. 1 0
      app/router.js
  3. 8 0
      app/service/student.js

+ 7 - 1
app/controller/student.js

@@ -12,7 +12,13 @@ class StudentController extends Controller {
     super(ctx);
     this.service = this.ctx.service.student;
   }
-
+  // GET
+  // 查询
+  async seek() {
+    const res = await this.service.seek(this.ctx.query);
+    console.log(res);
+    this.ctx.ok({ ...res });
+  }
 
 }
 

+ 1 - 0
app/router.js

@@ -40,6 +40,7 @@ module.exports = app => {
   router.get('questionnaire', '/api/train/questionnaire/show/:id', controller.questionnaire.show);
 
   // 学生表设置路由
+  router.get('sutdent', '/api/train/student/seek', controller.student.seek);
   router.resources('student', '/api/train/student', controller.student); // index、create、show、destroy
   router.post('student', '/api/train/student/update/:id', controller.student.update);
 

+ 8 - 0
app/service/student.js

@@ -13,6 +13,14 @@ class StudentService extends CrudService {
     this.model = this.ctx.model.Student;
   }
 
+  // 查询
+  async seek({ termid, skip, limit }) {
+    const students = await this.model.find({ termid, classid: null }).skip(Number(skip)).limit(Number(limit));
+    const total = await students.length;
+    const result = { total, students };
+    return result;
+  }
+
 }
 
 module.exports = StudentService;