lrf402788946 4 lat temu
rodzic
commit
04e4f2b9f3

+ 71 - 0
app/controller/tecinfo/.view_point.js

@@ -0,0 +1,71 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "title",
+      "publish_time",
+      "origin",
+      "brief",
+      "is_money",
+      "money",
+      "picture",
+      "filepath",
+      "video",
+      "content",
+      "remark",
+      "create_time",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "title",
+      "publish_time",
+      "origin",
+      "brief",
+      "is_money",
+      "money",
+      "picture",
+      "filepath",
+      "video",
+      "content",
+      "remark",
+      "create_time",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        title: "title",
+        publish_time: "publish_time",
+        origin: "origin",
+        is_money: "is_money",
+        "publish_time@start": "publish_time@start",
+        "publish_time@end": "publish_time@end",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/tecinfo/view_point.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.view_point.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 智库视点
+class View_pointController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.tecinfo.viewPoint;
+  }
+}
+module.exports = CrudController(View_pointController, meta);

+ 33 - 0
app/model/view_point.js

@@ -0,0 +1,33 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 智库视点表
+const view_point = {
+  user_id: { type: ObjectId }, //
+  title: { type: String }, // 标题
+  publish_time: { type: String }, // 时间
+  origin: { type: String, default: '网站管理员' }, // 来源
+  brief: { type: String }, // 简介
+  is_money: { type: Boolean, default: false }, // 是否收费
+  money: { type: Number }, // 收费金额
+  picture: { type: String }, // 图片
+  filepath: { type: String }, // 附件
+  video: { type: String }, // 视频
+  content: { type: String }, // 正文内容
+  remark: { type: String },
+  create_time: { type: String }, // 创建时间
+};
+const schema = new Schema(view_point, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ title: 1 });
+schema.index({ publish_time: 1 });
+schema.index({ origin: 1 });
+schema.index({ is_money: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('View_point', schema, 'view_point');
+};

+ 1 - 0
app/router.js

@@ -51,6 +51,7 @@ module.exports = app => {
   require('./router/tecinfo/news')(app); // 信息
   require('./router/tecinfo/science')(app); // 科技新闻
   require('./router/tecinfo/universal')(app); // 科学普及
+  require('./router/tecinfo/view_point')(app); // 智库视点
   // statistics
   require('./router/statistics/index')(app); // 首页统计
   // cysci

+ 12 - 0
app/router/tecinfo/view_point.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'tecinfo';
+  const target = 'viewPoint';
+  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);
+};

+ 15 - 0
app/service/tecinfo/view_point.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 智库视点
+class View_pointService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'view_point');
+    this.model = this.ctx.model.ViewPoint;
+  }
+}
+
+module.exports = View_pointService;