liuyu преди 4 години
родител
ревизия
f873988106
променени са 9 файла, в които са добавени 187 реда и са изтрити 0 реда
  1. 34 0
      app/controller/.contact.js
  2. 36 0
      app/controller/.news.js
  3. 17 0
      app/controller/contact.js
  4. 17 0
      app/controller/news.js
  5. 18 0
      app/model/contact.js
  6. 21 0
      app/model/news.js
  7. 8 0
      app/router.js
  8. 18 0
      app/service/contact.js
  9. 18 0
      app/service/news.js

+ 34 - 0
app/controller/.contact.js

@@ -0,0 +1,34 @@
+module.exports = {
+  create: {
+    requestBody: ["title", "content", "publish_time"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["title", "content", "publish_time"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        title: "title",
+        publish_time: "publish_time",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      asc: true,
+      count: true,
+    },
+  },
+};

+ 36 - 0
app/controller/.news.js

@@ -0,0 +1,36 @@
+module.exports = {
+  create: {
+    requestBody: ["title", "content", "publish_time","status","filedir","type"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["title", "content", "publish_time","status","filedir","type"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        title: "title",
+        publish_time: "publish_time",
+        status: "status",
+        type: "type"
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["publish_time"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 17 - 0
app/controller/contact.js

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

+ 17 - 0
app/controller/news.js

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

+ 18 - 0
app/model/contact.js

@@ -0,0 +1,18 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+const ContactSchema = {
+  title: { type: String, required: false, maxLength: 200 }, // 标题
+  content: { type: String, required: false }, // 内容
+  publish_time: { type: String, required: false, maxLength: 200 }, // 发布时间
+};
+
+const schema = new Schema(ContactSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Contact', schema, 'contact');
+};

+ 21 - 0
app/model/news.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+const NewsSchema = {
+  title: { type: String, required: false, maxLength: 200 }, // 标题
+  content: { type: String, required: false }, // 内容
+  filedir: { type: String, required: false }, // 封面图片
+  publish_time: { type: String, required: false, maxLength: 200 }, // 发布时间
+  type: { type: String, required: false, maxLength: 200 }, // 类型 0、会议简介 1、会议日程2、主办方介绍、3、协办方介绍4、专家介绍5、继续再教育申请表6、温馨提示
+  status: { type: String, required: false, maxLength: 200 }, // 0、开启1、禁用
+};
+
+const schema = new Schema(NewsSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('News', schema, 'news');
+};

+ 8 - 0
app/router.js

@@ -67,6 +67,14 @@ module.exports = app => {
   router.resources('uploadquestion', '/api/onlive/uploadquestion', controller.uploadquestion); // index、create、show、destroy
   router.post('uploadquestion', '/api/onlive/uploadquestion/update/:id', controller.uploadquestion.update);
 
+  // 联系我们表配置路由
+  router.resources('contact', '/api/onlive/contact', controller.contact); // index、create、show、destroy
+  router.post('contact', '/api/onlive/contact/update/:id', controller.contact.update);
+
+  // 会议简介表配置路由
+  router.resources('news', '/api/onlive/news', controller.news); // index、create、show、destroy
+  router.post('news', '/api/onlive/news/update/:id', controller.news.update);
+
   // 用户登录
   router.post('/api/onlive/login', controller.login.login);
   router.post('/api/onlive/trtclogin', controller.login.trtclogin);

+ 18 - 0
app/service/contact.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const moment = require('moment');
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class ContactService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'contact');
+    this.model = this.ctx.model.Contact;
+  }
+}
+
+module.exports = ContactService;

+ 18 - 0
app/service/news.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const moment = require('moment');
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class NewsService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'news');
+    this.model = this.ctx.model.News;
+  }
+}
+
+module.exports = NewsService;