瀏覽代碼

新建评分表

reloaded 5 年之前
父節點
當前提交
7097c105b8
共有 5 個文件被更改,包括 116 次插入0 次删除
  1. 49 0
      app/controller/.score.js
  2. 23 0
      app/controller/score.js
  3. 22 0
      app/model/score.js
  4. 4 0
      app/router.js
  5. 18 0
      app/service/score.js

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

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

+ 23 - 0
app/controller/score.js

@@ -0,0 +1,23 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.score.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 评分表管理
+class ScoreController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.score;
+  }
+
+  async queryteacher() {
+    const data = await this.service.queryteacher(this.ctx.request.query);
+    this.ctx.ok({ data });
+  }
+
+}
+
+module.exports = CrudController(ScoreController, meta);

+ 22 - 0
app/model/score.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 评分表
+const ScoreSchema = {
+  lessonid: { type: String, required: true, maxLength: 200 }, // 课程id
+  stuid: { type: String, required: true, maxLength: 200 }, // 学生id
+  teacherid: { type: String, required: true, maxLength: 200 }, // 教师id
+  score: { type: String, required: false, maxLength: 200 }, // 评分
+  remark: { type: String, required: false, maxLength: 2000 }, // 评价
+};
+
+
+const schema = new Schema(ScoreSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Score', schema, 'score');
+};

+ 4 - 0
app/router.js

@@ -143,4 +143,8 @@ module.exports = app => {
 
   // pc端登录
   router.post('/api/train/login', controller.login.login);// 登录
+
+  // 评分表设置路由
+  router.resources('score', '/api/train/score', controller.score); // index、create、show、destroy
+  router.post('score', '/api/train/score/update/:id', controller.score.update);
 };

+ 18 - 0
app/service/score.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 ScoreService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'score');
+    this.model = this.ctx.model.Score;
+  }
+
+}
+
+module.exports = ScoreService;