Преглед на файлове

更新作业表,问卷题库表

reloaded преди 5 години
родител
ревизия
dbc9d4f7f2
променени са 11 файла, в които са добавени 113 реда и са изтрити 181 реда
  1. 46 0
      app/controller/.question.js
  2. 49 0
      app/controller/.task.js
  3. 4 0
      app/controller/apply.js
  4. 2 36
      app/controller/question.js
  5. 2 36
      app/controller/task.js
  6. 1 1
      app/model/question.js
  7. 1 1
      app/model/task.js
  8. 4 8
      app/router.js
  9. 4 6
      app/service/apply.js
  10. 0 46
      app/service/question.js
  11. 0 47
      app/service/task.js

+ 46 - 0
app/controller/.question.js

@@ -0,0 +1,46 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!type',
+      '!topic',
+      'status',
+      'option'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'type',
+      'topic',
+      'status',
+      'option'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        type:'type',
+        topic:'topic',
+        status :'status',
+        option :'option'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 49 - 0
app/controller/.task.js

@@ -0,0 +1,49 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!code',
+      '!name',
+      '!title',
+      'status',
+      'question'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'code',
+      'name',
+      'title',
+      'status',
+      'question'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        code: 'code',
+        name: 'name',
+        title:'title',
+        status :'status',
+        question:'question'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 4 - 0
app/controller/apply.js

@@ -13,6 +13,10 @@ class ApplyController extends Controller {
     this.service = this.ctx.service.apply;
   }
 
+  async queryteacher() {
+    const data = await this.service.queryteacher(this.ctx.request.query);
+    this.ctx.ok({ data });
+  }
 
 }
 

+ 2 - 36
app/controller/question.js

@@ -2,6 +2,7 @@
 
 const _ = require('lodash');
 const Controller = require('egg').Controller;
+const meta = require('./.question.js');
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 科目管理
@@ -12,42 +13,7 @@ class QusetionController extends Controller {
     this.service = this.ctx.service.question;
   }
 
-  // POST
-  // 新建作业
-  async create() {
-    const res = await this.service.create(this.ctx.request.body);
-    this.ctx.ok({ msg: 'created', data: res });
-  }
-
-  // POST
-  // 根据id删除
-  async delete() {
-    const { id } = this.ctx.params;
-    await this.service.delete({ id });
-    this.ctx.ok({ msg: 'deleted' });
-  }
-
-  // POST
-  // 根据id更新信息
-  async update() {
-    await this.service.update(this.ctx.params, this.ctx.request.body);
-    this.ctx.ok({ msg: 'accepted' });
-  }
-
-  // GET
-  // 查询
-  async query() {
-    const res = await this.service.query(this.ctx.query);
-    this.ctx.ok({ ...res });
-  }
-
-  // GET
-  // 查询详情
-  async show() {
-    const res = await this.service.show(this.ctx.params);
-    this.ctx.ok({ msg: 'queried', data: res });
-  }
 
 }
 
-module.exports = QusetionController;
+module.exports = CrudController(QusetionController, meta);

+ 2 - 36
app/controller/task.js

@@ -2,6 +2,7 @@
 
 const _ = require('lodash');
 const Controller = require('egg').Controller;
+const meta = require('./.task.js');
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 作业管理
@@ -12,41 +13,6 @@ class TaskController extends Controller {
     this.service = this.ctx.service.task;
   }
 
-  // POST
-  // 新建作业
-  async create() {
-    const res = await this.service.create(this.ctx.request.body);
-    this.ctx.ok({ msg: 'created', data: res });
-  }
-
-  // POST
-  // 根据id删除
-  async delete() {
-    const { id } = this.ctx.params;
-    await this.service.delete({ id });
-    this.ctx.ok({ msg: 'deleted' });
-  }
-
-  // POST
-  // 根据id更新信息
-  async update() {
-    await this.service.update(this.ctx.params, this.ctx.request.body);
-    this.ctx.ok({ msg: 'accepted' });
-  }
-  // GET
-  // 查询
-  async query() {
-    const res = await this.service.query(this.ctx.query);
-    this.ctx.ok({ msg: 'queried', data: res });
-  }
-
-  // GET
-  // 查询详情
-  async show() {
-    const res = await this.service.show(this.ctx.params);
-    this.ctx.ok({ msg: 'queried', data: res });
-  }
-
 }
 
-module.exports = TaskController;
+module.exports = CrudController(TaskController, meta);

+ 1 - 1
app/model/question.js

@@ -5,7 +5,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 // 选项详情
 const optionInfo = new Schema({
   number: { type: String, required: false, maxLength: 200 }, // 序号
-  option_name: { type: String, required: false, maxLength: 200 }, // 名称
+  opname: { type: String, required: false, maxLength: 200 }, // 名称
 });
 
 // 问卷题库表

+ 1 - 1
app/model/task.js

@@ -5,7 +5,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 // 选项详情
 const optionInfo = new Schema({
   number: { type: String, required: false, maxLength: 200 }, // 序号
-  option_name: { type: String, required: false, maxLength: 200 }, // 名称
+  opname: { type: String, required: false, maxLength: 200 }, // 名称
 });
 
 // 问题详情

+ 4 - 8
app/router.js

@@ -14,21 +14,16 @@ module.exports = app => {
   // 教师表设置路由
   router.get('teacher', '/api/train/teacher/show/:id', controller.teacher.show);
   router.resources('teacher', '/api/train/teacher', controller.teacher); // index、create、show、destroy
+  router.post('teacher', '/api/train/teacher/update/:id', controller.teacher.update);
   router.post('teacher', '/api/train/teacher/status', controller.teacher.status);
 
   // 作业表配置路由
-  router.post('task', '/api/train/task', controller.task.create);
-  router.delete('task', '/api/train/task/:id', controller.task.delete);
+  router.resources('task', '/api/train/task', controller.task); // index、create、show、destroy
   router.post('task', '/api/train/task/update/:id', controller.task.update);
-  router.get('task', '/api/train/task', controller.task.query);
-  router.get('task', '/api/train/task/show/:id', controller.task.show);
 
   // 问卷题库表配置路由
-  router.post('question', '/api/train/question', controller.question.create);
-  router.delete('question', '/api/train/question/:id', controller.question.delete);
+  router.resources('question', '/api/train/question', controller.question); // index、create、show、destroy
   router.post('question', '/api/train/question/update/:id', controller.question.update);
-  router.get('question', '/api/train/question', controller.question.query);
-  router.get('question', '/api/train/question/show/:id', controller.question.show);
 
   // 问卷表配置路由
   router.post('questionnaire', '/api/train/questionnaire', controller.questionnaire.create);
@@ -85,6 +80,7 @@ module.exports = app => {
   router.post('teaplan', '/api/train/teaplan/update/:id', controller.teaplan.update);
 
   // 教师申请讲课表设置路由
+  router.get('apply', '/api/train/apply/queryteacher', controller.apply.queryteacher);
   router.resources('apply', '/api/train/apply', controller.apply); // index、create、show、destroy
   router.post('apply', '/api/train/apply/update/:id', controller.apply.update);
 

+ 4 - 6
app/service/apply.js

@@ -15,9 +15,9 @@ class ApplyService extends CrudService {
   }
 
   // 查询
-  async query({ skip, limit, ...num }) {
-    const total = await this.model.find(num).length;
-    const data = await this.model.find(num).skip(Number(skip)).limit(Number(limit));
+  async queryteacher(num) {
+    console.log(num);
+    const data = await this.model.find(num);
     console.log(data);
     const teachers = [];
     for (const _data of data) {
@@ -25,9 +25,7 @@ class ApplyService extends CrudService {
       const teacher = await this.tmodel.findById(teacherid);
       teachers.push(teacher);
     }
-    const newdata = { data, teachers };
-    const result = { total, newdata };
-    return result;
+    return teachers;
   }
 
 }

+ 0 - 46
app/service/question.js

@@ -13,52 +13,6 @@ class QuestionService extends CrudService {
     this.model = this.ctx.model.Question;
   }
 
-  // 插入问卷题目
-  async create(data) {
-    const { type, topic } = data;
-    assert(type, '类型不能为空');
-    assert(topic, '题目不能为空');
-    // 插入数据时默认状态为1
-    const newdata = { ...data, status: '1' };
-    const entity = await this.model.create(newdata);
-    return await this.fetch({ id: entity.id });
-  }
-
-  // 根据id删除
-  async delete({ id }) {
-    await this.model.findByIdAndDelete(id);
-    return 'deleted';
-  }
-
-  // 根据id更新问卷题目
-  async upadate({ id }, data) {
-    const question = await this.model.findById(id);
-    if (question.type) {
-      question.code = data.code;
-    }
-    if (question.topic) {
-      question.name = data.name;
-    }
-    if (question.status) {
-      question.status = data.status;
-    }
-    question.option = data.option;
-    return await question.save();
-  }
-
-  // 查询
-  async query({ skip, limit, ...num }) {
-    const total = await (await this.model.find(num)).length;
-    const data = await this.model.find(num).skip(Number(skip)).limit(Number(limit));
-    const result = { total, data };
-    return result;
-  }
-
-  // 查询详情
-  async show({ id }) {
-    return await this.model.findById(id);
-  }
-
 }
 
 module.exports = QuestionService;

+ 0 - 47
app/service/task.js

@@ -13,53 +13,6 @@ class TaskService extends CrudService {
     this.model = this.ctx.model.Task;
   }
 
-  // 插入作业
-  async create(data) {
-    const { code, name, title } = data;
-    assert(code, '科目代码不能为空');
-    assert(name, '科目名称不能为空');
-    assert(title, '标题不能为空');
-    // 插入数据时默认状态为1
-    const newdata = { ...data, status: '1' };
-    const entity = await this.model.create(newdata);
-    return await this.fetch({ id: entity.id });
-  }
-
-  // 根据id删除
-  async delete({ id }) {
-    await this.model.findByIdAndDelete(id);
-    return 'deleted';
-  }
-
-  // 根据id更新作业信息
-  async upadate({ id }, data) {
-    const task = await this.model.findById(id);
-    if (task.code) {
-      task.code = data.code;
-    }
-    if (task.name) {
-      task.name = data.name;
-    }
-    if (task.title) {
-      task.title = data.title;
-    }
-    if (task.status) {
-      task.status = data.status;
-    }
-    task.question = data.question;
-    return await task.save();
-  }
-
-  // 查询
-  async query({ skip, limit, ...num }) {
-    return await this.model.find(num).skip(Number(skip)).limit(Number(limit));
-  }
-
-  // 查询详情
-  async show({ id }) {
-    return await this.model.findById(id);
-  }
-
 }
 
 module.exports = TaskService;