asd123a20 hace 3 años
padre
commit
535d5e1faa
Se han modificado 3 ficheros con 11 adiciones y 6 borrados
  1. 6 0
      app/model/Content.js
  2. 4 5
      app/service/content.js
  3. 1 1
      config/config.default.js

+ 6 - 0
app/model/Content.js

@@ -43,6 +43,12 @@ module.exports = app => {
     columnList: {
       type: Array,
     },
+    year: {
+      type: String,
+    },
+    date: {
+      type: String,
+    },
   });
   return mongoose.model('Content', ContentSchema);
 };

+ 4 - 5
app/service/content.js

@@ -4,7 +4,7 @@ const Service = require('egg').Service;
 const assert = require('assert');
 const moment = require('moment');
 class ContentService extends Service {
-  async create({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList }) {
+  async create({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, year, datte }) {
     assert(title, '标题不存在');
     assert(shortTitle, '短标题不存在');
     assert(slug, '摘要不存在');
@@ -13,17 +13,17 @@ class ContentService extends Service {
     const { Content: model } = this.ctx.model;
     const createAt = moment().format('x');
     try {
-      await model.create({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, createAt });
+      await model.create({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, createAt, year, datte });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error({ errcode: -2001, errmsg: '添加失败' });
     }
   }
-  async update({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, id }) {
+  async update({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, id, year, datte }) {
     assert(id, 'id不存在');
     const { Content: model } = this.ctx.model;
     try {
-      await model.findByIdAndUpdate(id, { title, shortTitle, slug, thumbnail, annex, content, istop, columnList });
+      await model.findByIdAndUpdate(id, { title, shortTitle, slug, thumbnail, annex, content, istop, columnList, year, datte });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error({ errcode: -2001, errmsg: '修改失败' });
@@ -59,7 +59,6 @@ class ContentService extends Service {
         res = await model.where('columnList').in(code).select({ content: false })
           .skip(Number(skip) * Number(limit))
           .limit(Number(limit));
-        // res = await model.find({ code, content: false }).skip(skip * limit).limit(limit);
       } else {
         res = await model.where('columnList').in(code).select({ content: false });
       }

+ 1 - 1
config/config.default.js

@@ -44,7 +44,7 @@ module.exports = appInfo => {
   config.userSecret = '123456';
   // 数据库配置
   config.mongoose = {
-    url: 'mongodb://127.0.0.1/example',
+    url: 'mongodb://127.0.0.1:27018/example',
     options: {},
   };
   // 异常捕获