guhongwei 3 gadi atpakaļ
vecāks
revīzija
da23fa1496

+ 58 - 0
app/controller/patent/.patentroom.js

@@ -0,0 +1,58 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "time_id",
+      "p1_id",
+      "p1",
+      "p2_id",
+      "p2",
+      "create_time",
+      "last_time",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "time_id",
+      "p1_id",
+      "p1",
+      "p2_id",
+      "p2",
+      "create_time",
+      "last_time",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        time_id: "time_id",
+        p1_id: "p1_id",
+        p1: "p1",
+        p2_id: "p2_id",
+        p2: "p2",
+        create_time: "create_time",
+        last_time: "last_time",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/patent/patentroom.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.patentroom.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 交易订单
+class PatentroomController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.patent.patentroom;
+  }
+}
+module.exports = CrudController(PatentroomController, meta);

+ 30 - 0
app/model/patent/patentroom.js

@@ -0,0 +1,30 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+const { ObjectId } = require('mongoose').Types;
+// 专利资讯服务房间表
+const patentroom = {
+  time_id: { type: ObjectId }, // 时间id
+  p1_id: { type: ObjectId, required: true }, // 第一个人id
+  p1: { type: String, required: false }, // 第一个人名
+  p2_id: { type: ObjectId, required: true }, // 第二个人id
+  p2: { type: String, required: false }, // 第二个人名
+  create_time: {
+    type: String,
+    default: moment().format('YYYY-MM-DD HH:mm:ss'),
+  },
+  last_time: { type: String }, // 最后发言时间
+};
+const schema = new Schema(patentroom, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ time_id: 1 });
+schema.index({ p1_id: 1 });
+schema.index({ p2_id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Patentroom', schema, 'patent_room');
+};

+ 1 - 0
app/router.js

@@ -77,4 +77,5 @@ module.exports = app => {
   require('./router/patent/purchase')(app); // 求购
   require('./router/patent/tradeorder')(app); // 交易订单
   // 2021-08-20-重定义
+  require('./router/patent/patentroom')(app); // 交易订单
 };

+ 12 - 0
app/router/patent/patentroom.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'patent';
+  const target = 'patentroom';
+  router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
+};

+ 18 - 0
app/service/patent/patentroom.js

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