소스 검색

新建全年计划模板表

reloaded 5 년 전
부모
커밋
b44a83082c
5개의 변경된 파일99개의 추가작업 그리고 0개의 파일을 삭제
  1. 37 0
      app/controller/.trainmodel.js
  2. 18 0
      app/controller/trainmodel.js
  3. 22 0
      app/model/trainmodel.js
  4. 4 0
      app/router.js
  5. 18 0
      app/service/trainmodel.js

+ 37 - 0
app/controller/.trainmodel.js

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: ["total", "day", "color", "batchnum", "classnum"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["total", "day", "color", "batchnum", "classnum"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        total: "total",
+        day: "day",
+        color: "color",
+        batchnum: "batchnum",
+        classnum: "classnum",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 18 - 0
app/controller/trainmodel.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+const meta = require('./.trainmodel.js');
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 全年计划模板管理
+class TrainmodelController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.trainmodel;
+  }
+
+}
+
+module.exports = CrudController(TrainmodelController, meta);

+ 22 - 0
app/model/trainmodel.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 全年计划模板表
+const TrainmodelSchema = {
+  total: { type: String, required: false, maxLength: 200 }, // 总人数
+  day: { type: String, required: false, maxLength: 200 }, // 课程所需天数
+  color: { type: [ String ], required: false }, // 默认颜色
+  batchnum: { type: String, required: false, maxLength: 200 }, // 默认期下生成的批次数
+  classnum: { type: String, required: false, maxLength: 200 }, // 默认批次下生成的班级数
+};
+
+
+const schema = new Schema(TrainmodelSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Trainmodel', schema, 'trainmodel');
+};

+ 4 - 0
app/router.js

@@ -185,4 +185,8 @@ module.exports = app => {
   // 课程模板表设置路由
   router.resources('lessonmode', '/api/train/lessonmode', controller.lessonmode); // index、create、show、destroy
   router.post('lessonmode', '/api/train/lessonmode/update/:id', controller.lessonmode.update);
+
+  // 全年计划模板表设置路由
+  router.resources('trainmodel', '/api/train/trainmodel', controller.trainmodel); // index、create、show、destroy
+  router.post('trainmodel', '/api/train/trainmodel/update/:id', controller.trainmodel.update);
 };

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