浏览代码

新增栏目表

reloaded 5 年之前
父节点
当前提交
aac3ccc634
共有 8 个文件被更改,包括 108 次插入3 次删除
  1. 40 0
      app/controller/.column.js
  2. 3 0
      app/controller/.user.js
  3. 19 0
      app/controller/column.js
  4. 20 0
      app/model/column.js
  5. 1 0
      app/model/user.js
  6. 4 0
      app/router.js
  7. 18 0
      app/service/column.js
  8. 3 3
      app/service/user.js

+ 40 - 0
app/controller/.column.js

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

+ 3 - 0
app/controller/.user.js

@@ -24,6 +24,7 @@ module.exports = {
       "is_del",
       "role",
       "token",
+      "columnid"
     ],
   },
   destroy: {
@@ -56,6 +57,7 @@ module.exports = {
       "is_del",
       "role",
       "token",
+      "columnid"
     ],
   },
   show: {
@@ -90,6 +92,7 @@ module.exports = {
         is_del: "is_del",
         role: "role",
         token: "token",
+        columnidg :"columnid"
       },
     },
     service: "query",

+ 19 - 0
app/controller/column.js

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

+ 20 - 0
app/model/column.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+
+// 栏目表
+const ColumnSchema = {
+  name: { type: String, required: true, maxLength: 500 }, // 栏目名称
+  site: { type: String, required: false, maxLength: 500 }, // 栏目位置
+};
+
+
+const schema = new Schema(ColumnSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Column', schema, 'affairs_column');
+};

+ 1 - 0
app/model/user.js

@@ -28,6 +28,7 @@ const UserSchema = {
   is_del: { type: String, required: false, maxLength: 200 }, // 是否删除,0-否,1-是
   role: { type: String, required: false, maxLength: 200 }, // 1-管理员,2-个人,3-企业管理员
   token: { type: String, required: false, maxLength: 500 }, // 令牌
+  columnid: [ String ],
 };
 
 

+ 4 - 0
app/router.js

@@ -38,4 +38,8 @@ module.exports = app => {
   // 用户登陆
   router.post('user', '/api/user/login', controller.user.login);
 
+  // 栏目表设置路由
+  router.resources('column', '/api/market/column', controller.column); // index、create、show、destroy
+  router.post('column', '/api/market/column/update/:id', controller.column.update);
+
 };

+ 18 - 0
app/service/column.js

@@ -0,0 +1,18 @@
+'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 ColumnService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'column');
+    this.model = this.ctx.model.Column;
+  }
+
+}
+
+module.exports = ColumnService;

+ 3 - 3
app/service/user.js

@@ -60,7 +60,7 @@ class UserService extends CrudService {
     user.is_del = data.is_del;
     user.role = data.role;
     user.token = data.token;
-
+    user.columnid = data.columnid;
     return await user.save();
   }
 
@@ -84,11 +84,11 @@ class UserService extends CrudService {
   }
 
   // 创建登录Token
-  async createJwt({ id, name, phone, is_qy, img_path, email, resume, major, office_phone, profession, role, status }) {
+  async createJwt({ id, name, phone, is_qy, img_path, email, resume, major, office_phone, profession, role, status, columnid }) {
     const { secret, expiresIn = '1d', issuer } = this.config.jwt;
     const subject = phone;
     // const _userid = id;
-    const res = { name, phone, is_qy, id, img_path, email, resume, major, office_phone, profession, role, status };
+    const res = { name, phone, is_qy, id, img_path, email, resume, major, office_phone, profession, role, status, columnid };
     const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
     return token;
   }