guhongwei 4 years ago
parent
commit
f3c7087096
5 changed files with 92 additions and 0 deletions
  1. 35 0
      app/controller/.imgtxtdock.js
  2. 16 0
      app/controller/imgtxtdock.js
  3. 20 0
      app/model/imgtxtdock.js
  4. 4 0
      app/router.js
  5. 17 0
      app/service/imgtxtdock.js

+ 35 - 0
app/controller/.imgtxtdock.js

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

+ 16 - 0
app/controller/imgtxtdock.js

@@ -0,0 +1,16 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.imgtxtdock.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+//
+class ImgtxtdockController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.imgtxtdock;
+  }
+}
+
+module.exports = CrudController(ImgtxtdockController, meta);

+ 20 - 0
app/model/imgtxtdock.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 栏目表
+const ImgtxtdockSchema = {
+  name: { type: String, required: true, maxLength: 500 }, // 名称
+  type: { type: String, required: false, maxLength: 500 }, // 类别
+  dock_id: { type: String, required: false, maxLength: 500 }, // 展会id
+};
+
+
+const schema = new Schema(ImgtxtdockSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Imgtxtdock', schema, 'imgtxtdock');
+};

+ 4 - 0
app/router.js

@@ -110,4 +110,8 @@ module.exports = app => {
   router.resources('flower', '/api/live/flower', controller.flower); // index、create、show、destroy
   router.post('flower', '/api/live/flower/update/:id', controller.flower.update);
 
+  // 花表
+  router.resources('imgtxtdock', '/api/live/imgtxtdock', controller.imgtxtdock); // index、create、show、destroy
+  router.post('imgtxtdock', '/api/live/imgtxtdock/update/:id', controller.imgtxtdock.update);
+
 };

+ 17 - 0
app/service/imgtxtdock.js

@@ -0,0 +1,17 @@
+'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 ImgtxtdockService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'imgtxtdock');
+    this.model = this.ctx.model.Imgtxtdock;
+  }
+}
+
+module.exports = ImgtxtdockService;