Quellcode durchsuchen

增加学生问卷上传答案功能

liuyu vor 5 Jahren
Ursprung
Commit
64f940aa63

+ 50 - 0
app/controller/.uploadquestion.js

@@ -0,0 +1,50 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!termid',
+      '!batchid',
+      '!classid',
+      '!studentid',
+      '!questionnaireid',
+      'answers'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'termid',
+      'batchid',
+      'classid',
+      'studentid',
+      'questionnaireid',
+      'answers'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        termid : 'termid',
+        batchid: 'batchid',
+        classid : 'classid',
+        studentid : 'studentid'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 19 - 0
app/controller/uploadquestion.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.uploadquestion.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 学生上传问卷管理
+class UploadquestionController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.uploadquestion;
+  }
+
+
+}
+
+module.exports = CrudController(UploadquestionController, meta);

+ 1 - 0
app/model/questionnaire.js

@@ -7,6 +7,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 const QuestionnaireSchema = {
   name: { type: String, required: true, maxLength: 200 }, // 问卷名称
   num: { type: String, required: true, maxLength: 200 }, // 序号
+  status: { type: String, required: true, maxLength: 200, defalut: 0 }, // 状态0、开启1、关闭
   question: [ String ], // 问题code
 };
 

+ 29 - 0
app/model/uploadquestion.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 答案详情
+const answerInfo = new Schema({
+  questionid: { type: String, required: false, maxLength: 200 }, // 问题id
+  answer: { type: String, required: false, maxLength: 200 }, // 答案
+});
+
+// 学生上传问卷表
+const UploadquestionSchema = {
+  termid: { type: String, required: true, maxLength: 200 }, // 期id
+  batchid: { type: String, required: true, maxLength: 200 }, // 批次id
+  classid: { type: String, required: true, maxLength: 200 }, // 班级id
+  studentid: { type: String, required: true, maxLength: 200 }, // 学生id
+  questionnaireid: { type: String, required: false, maxLength: 200 }, // 问卷id
+  answers: { type: [ answerInfo ], select: true }, // 选项
+};
+
+
+const schema = new Schema(UploadquestionSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Uploadquestion', schema, 'uploadquestion');
+};

+ 4 - 0
app/router.js

@@ -102,6 +102,10 @@ module.exports = app => {
   router.resources('uploadtask', '/api/train/uploadtask', controller.uploadtask); // index、create、show、destroy
   router.post('uploadtask', '/api/train/uploadtask/update/:id', controller.uploadtask.update);
 
+  // 学生上传问卷表设置路由
+  router.resources('uploadquestion', '/api/train/uploadquestion', controller.uploadquestion); // index、create、show、destroy
+  router.post('uploadquestion', '/api/train/uploadquestion/update/:id', controller.uploadquestion.update);
+
   // 考勤表设置路由
   router.resources('attendance', '/api/train/attendance', controller.attendance); // index、create、show、destroy
   router.post('attendance', '/api/train/attendance/update/:id', controller.attendance.update);

+ 18 - 0
app/service/uploadquestion.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class UploadquestionService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'uploadquestion');
+    this.model = this.ctx.model.Uploadquestion;
+  }
+
+}
+
+module.exports = UploadquestionService;