reloaded 5 years ago
parent
commit
39fb8add09
5 changed files with 131 additions and 0 deletions
  1. 64 0
      app/controller/.demand.js
  2. 18 0
      app/controller/demand.js
  3. 27 0
      app/model/demand.js
  4. 4 0
      app/router.js
  5. 18 0
      app/service/demand.js

+ 64 - 0
app/controller/.demand.js

@@ -0,0 +1,64 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "!field",
+      "!budget",
+      "enddate",
+      "problem",
+      "condition",
+      "type",
+      "uid",
+      "is_display",
+      "status",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "name",
+      "field",
+      "budget",
+      "enddate",
+      "problem",
+      "condition",
+      "type",
+      "uid",
+      "is_display",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        field: "field",
+        budget: "budget",
+        enddate: "enddate",
+        problem: "problem",
+        condition: "condition",
+        type: "type",
+        uid: "uid",
+        is_display: "is_display",
+        status: "status",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 18 - 0
app/controller/demand.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.demand.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 部门表管理
+class DemandController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.demand;
+  }
+
+}
+
+module.exports = CrudController(DemandController, meta);

+ 27 - 0
app/model/demand.js

@@ -0,0 +1,27 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 需求表
+const DemandSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 需求技术名称
+  field: { type: String, required: true, maxLength: 200 }, // 所属领域
+  budget: { type: String, required: true, maxLength: 200 }, // 拟投入预算 (万)
+  enddate: { type: String, required: false, maxLength: 200 }, // 需求截止日期
+  problem: { type: String, required: false, maxLength: 500 }, // 难题或瓶颈问题
+  condition: { type: String, required: false, maxLength: 500 }, // 企业解决技术需求已具备的条件
+  type: { type: String, required: false, maxLength: 200 }, // 合作方式
+  uid: { type: String, required: false, maxLength: 200 }, // 发布人用户id
+  is_display: { type: String, required: false, maxLength: 200 }, // 是否在网页上显示,0-显示,1-不显示
+  status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态,0-草稿,1-未审核,2-已审核
+};
+
+
+const schema = new Schema(DemandSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Demand', schema, 'demand');
+};

+ 4 - 0
app/router.js

@@ -39,4 +39,8 @@ module.exports = app => {
   // 专家表设置路由
   router.resources('expert', '/api/live/expert', controller.expert); // index、create、show、destroy
   router.post('expert', '/api/live/expert/update/:id', controller.expert.update);
+
+  // 需求表设置路由
+  router.resources('demand', '/api/live/demand', controller.demand); // index、create、show、destroy
+  router.post('demand', '/api/live/demand/update/:id', controller.demand.update);
 };

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