sky 4 年之前
父節點
當前提交
69d23f7fe0
共有 6 個文件被更改,包括 34 次插入33 次删除
  1. 8 24
      analysis/index.js
  2. 10 2
      controllers/groups_controller.js
  3. 8 0
      controllers/students_controller.js
  4. 2 2
      package.json
  5. 4 3
      routes/index.js
  6. 2 2
      services/groupService.js

+ 8 - 24
analysis/index.js

@@ -8,28 +8,6 @@ const JsonHandler = require("../config/jsonHandler");
 const StudentConstructor = require("../models/constructors/StudentConstructor");
 const GroupConstructor = require("../models/constructors/GroupConstructor");
 const GroupService = require("../services/groupService");
-
-const userSchema = {
-  'id': Number,
-  'created_time': String,
-  'email': String,
-  'is_valid': String,
-  'name': String,
-  'password': String,
-  'phone': String,
-  'photo': Uint32Array,
-  'role': String,
-  'signature': String,
-  'username': String
-}
-
-const userSchema2 = {
-  '组号': Number,
-  '姓名': String,
-  '学号': String,
-  '组长手机号': String
-}
-
 class Analysis {
   async run() {
     try {
@@ -47,8 +25,14 @@ class Analysis {
       console.log(data); 
       Database.close();
       */
-      this.fromJsonToDatabase()
-      // await this.getInterfaceTestStatistics()
+      await Database.asyncConnect();
+      let filter = {
+        group: 5
+      };
+      let data = await GroupService.findOne(filter);
+      console.log(data); 
+      Database.close();
+     
     } catch (errors) {
       console.error(errors);
     }

+ 10 - 2
controllers/groups_controller.js

@@ -4,8 +4,16 @@ class GroupsController {
 
     static findAll(request, h) {
       try {
-        const filter = request.query;
-        return GroupService.getAll(filter);
+        const project= "group projects members";
+        return GroupService.getAll({}, project);
+      } catch(errors) {
+        return h.response(errors).code(422);
+      }
+    }
+    static findOneByGroupId(request, h) {
+      try {
+        const filter = {group: request.params.groupId};
+        return GroupService.findOne(filter);
       } catch(errors) {
         return h.response(errors).code(422);
       }

+ 8 - 0
controllers/students_controller.js

@@ -10,6 +10,14 @@ class StudentsController {
         return h.response(errors).code(422);
       }
     }
+    static findOneByStudentId(request, h) {
+      try {
+        const filter = {studentId: request.params.studentId};
+        return StudentService.findOne(filter);
+      } catch(errors) {
+        return h.response(errors).code(422);
+      }
+    }
     static async create(request, h) {
         try {
             const student = await StudentService.create(request.payload);

+ 2 - 2
package.json

@@ -4,8 +4,8 @@
   "description": "",
   "main": "index.js",
   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1",
-    "serve": "node index.js"
+    "serve": "node index.js",
+    "test": "node ./analysis"
   },
   "author": "",
   "license": "ISC",

+ 4 - 3
routes/index.js

@@ -5,9 +5,10 @@ const GroupsController = require('../controllers/groups_controller');
 exports.plugin = {
     pkg: require('../package.json'),
     register: async function(server, options) {
-        // server.route({ path: '/students/{id}', method: 'GET', handler: StudentsController.findById });
-        server.route({ path: '/students/', method: 'GET', handler: StudentsController.findAll });
-        server.route({ path: '/groups/', method: 'GET', handler: GroupsController.findAll });
+        // server.route({ path: '/students', method: 'GET', handler: StudentsController.findAll });
+        server.route({ path: '/students/{studentId}', method: 'GET', handler: StudentsController.findOneByStudentId });
+        server.route({ path: '/groups', method: 'GET', handler: GroupsController.findAll });
+        server.route({ path: '/groups/{groupId}', method: 'GET', handler: GroupsController.findOneByGroupId });
         // server.route({ path: '/students/', method: 'POST', handler: StudentsController.create });
 
         // server.route({ path: '/group/{groupId}', method: 'GET', handler: GroupsController.findByGroupId });

+ 2 - 2
services/groupService.js

@@ -2,8 +2,8 @@ const Group = require('../models/group');
 
 
 class GroupService {
-    static async getAll(filter) {
-        return Group.find(filter);
+    static async getAll(filter, project) {
+        return Group.find(filter, project);
     }
     static async findOne(filter) {
         return Group.findOne(filter);