lrf402788946 4 yıl önce
ebeveyn
işleme
9319302a5a

+ 59 - 0
app/controller/tecinfo/.universal.js

@@ -0,0 +1,59 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "type",
+      "title",
+      "origin",
+      "create_time",
+      "img_url",
+      "file_url",
+      "content",
+      'user_id',
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "type",
+      "title",
+      "origin",
+      "create_time",
+      "img_url",
+      "file_url",
+      "content",
+      'user_id',
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        type:"type",
+        title:"title",
+        user_id:"user_id",
+        origin:"origin",
+        "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/universal.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.universal.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科学普及
+class UniversalController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.tecinfo.universal;
+  }
+}
+module.exports = CrudController(UniversalController, meta);

+ 30 - 0
app/model/universal.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 { ObjectId } = require('mongoose').Types;
+// 科技普及表
+const universal = {
+  type: { type: String }, // 类型
+  title: { type: String }, // 标题
+  origin: { type: String }, // 来源
+  create_time: { type: String }, // 创建时间
+  img_url: { type: Array }, // //图片路径
+  file_url: { type: Array }, // 文件路径
+  content: { type: String }, // 内容
+  user_id: { type: ObjectId }, // 创建用户
+  remark: { type: String },
+};
+const schema = new Schema(universal, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ type: 1 });
+schema.index({ title: 1 });
+schema.index({ create_time: 1 });
+schema.index({ user_id: 1 });
+schema.index({ origin: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Universal', schema, 'universal');
+};

+ 1 - 0
app/router.js

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

+ 12 - 0
app/router/tecinfo/universal.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 = 'universal';
+  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/universal.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 UniversalService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'universal');
+    this.model = this.ctx.model.Universal;
+  }
+}
+
+module.exports = UniversalService;