From b35fd83e77bd2d8c81bec3313e9aad812fe912d2 Mon Sep 17 00:00:00 2001 From: "yhui.yang" Date: Fri, 28 Jul 2017 17:21:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dfirefox=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Footer/Footer.js | 21 +++++++++++---------- client/components/Footer/Footer.scss | 15 +++++++++------ client/containers/Home/Home.js | 27 +++++++++++++-------------- client/containers/Home/Home.scss | 2 ++ 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/client/components/Footer/Footer.js b/client/components/Footer/Footer.js index b5af007c..9d776e92 100644 --- a/client/components/Footer/Footer.js +++ b/client/components/Footer/Footer.js @@ -14,18 +14,19 @@ class Footer extends Component { 'background': 'url(./image/footer-bac.jpg)' } return ( -
- -
- { this.props.footList.map(function(item,i){ - return - }) } -
-

Copyright © 2017

- YMFF出品 @ YMFF +
+
+
+ { this.props.footList.map(function(item,i){ + return + }) } +
+

Copyright © 2017

+ YMFF出品 @ YMFF +
+
-
) } diff --git a/client/components/Footer/Footer.scss b/client/components/Footer/Footer.scss index bca0d18c..fd4b37fd 100644 --- a/client/components/Footer/Footer.scss +++ b/client/components/Footer/Footer.scss @@ -1,9 +1,12 @@ @import '../../styles/common.scss'; @import '../../styles/mixin.scss'; +.footer-wrapper{ + width: 100%; +} .footer{ @include wrap-width-limit; - margin: 0px auto; + margin: 0 auto; clear: both; font-size: 12px; background: #000c15; @@ -25,7 +28,7 @@ .footerMask{ @include wrap-width-limit; position: absolute; - top: 0px; + top: 0; height: 100%; width: 100%; background-color: #404040; @@ -34,8 +37,8 @@ } .footContent{ @include row-width-limit; - width:90%; - margin:0px auto; + //width:90%; + margin:0 auto; overflow: hidden; position: relative; z-index: 2; @@ -45,7 +48,7 @@ width: 25%; float: left; div{ - margin: 6px 0px; + margin: 6px 0; } a{ font-weight: 200; @@ -68,6 +71,6 @@ margin: 0 auto 12px; font-weight: 500; position: relative; - text-indent: 0em; + text-indent: 0; } } diff --git a/client/containers/Home/Home.js b/client/containers/Home/Home.js index e04d78a7..f5a2f13c 100644 --- a/client/containers/Home/Home.js +++ b/client/containers/Home/Home.js @@ -15,7 +15,8 @@ import QueueAnim from 'rc-queue-anim'; const oneAnim = { y: '+=30', opacity: 0, type: 'from', ease: 'easeOutQuad' }; const imgAnim = { y: '+=50', opacity: 0, type: 'from', ease: 'easeOutQuad', duration: '1500'}; const style = { - 'height':'100%', + // 'height':'100%', + // 'height':'7rem', 'width':'100%', 'background': 'url(./image/bg-img.jpg) no-repeat', 'backgroundSize':'100% 100%' @@ -37,19 +38,17 @@ const HomeGuest = (props) => ( - - - - -
- -
- -
-
+ + + + + + +
diff --git a/client/containers/Home/Home.scss b/client/containers/Home/Home.scss index 064eff06..4846bf19 100644 --- a/client/containers/Home/Home.scss +++ b/client/containers/Home/Home.scss @@ -27,6 +27,8 @@ $color-black-lighter: #404040; color: $color-white; } .img-container{ + width: 100%; + //height: 5rem; margin-bottom: -.3rem; img{ width: 100%; From 37d95b5ece705bca157e614863975e5b470d950e Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Fri, 28 Jul 2017 17:29:17 +0800 Subject: [PATCH 2/2] feat: add user nav info --- doc/build/api.html | 140 ++++++-- doc/build/index.html | 42 ++- .../static/server/controllers/base.js.html | 101 +++--- .../static/server/controllers/group.js.html | 130 ++++--- .../server/controllers/interface.js.html | 187 ++++++---- .../static/server/controllers/log.js.html | 9 +- .../static/server/controllers/project.js.html | 333 +++++++++--------- .../static/server/controllers/user.js.html | 218 ++++++++---- exampleCode/api/user/nav.json | 12 + server/controllers/user.js | 55 ++- server/models/group.js | 6 + server/router.js | 1 + server_dist/controllers/user.js | 112 ++++++ server_dist/models/group.js | 7 + server_dist/router.js | 1 + 15 files changed, 927 insertions(+), 427 deletions(-) create mode 100644 exampleCode/api/user/nav.json diff --git a/doc/build/api.html b/doc/build/api.html index 208c6f69..dd616356 100644 --- a/doc/build/api.html +++ b/doc/build/api.html @@ -131,6 +131,10 @@
  • /user/search
  • + +
  • + /user/nav +
  • @@ -252,7 +256,7 @@

    源码位置: - ./server/controllers/group.js:12 + ./server/controllers/group.js:10

    @@ -335,7 +339,7 @@

    源码位置: - ./server/controllers/group.js:54 + ./server/controllers/group.js:64

    @@ -397,7 +401,7 @@

    源码位置: - ./server/controllers/group.js:74 + ./server/controllers/group.js:83

    @@ -469,7 +473,7 @@

    源码位置: - ./server/controllers/group.js:108 + ./server/controllers/group.js:120

    @@ -569,7 +573,7 @@

    源码位置: - ./server/controllers/user.js:14 + ./server/controllers/user.js:17

    @@ -656,7 +660,7 @@

    源码位置: - ./server/controllers/user.js:58 + ./server/controllers/user.js:62

    @@ -689,7 +693,7 @@

    源码位置: - ./server/controllers/user.js:151 + ./server/controllers/user.js:159

    @@ -785,7 +789,7 @@

    源码位置: - ./server/controllers/user.js:224 + ./server/controllers/user.js:228

    @@ -882,7 +886,7 @@

    源码位置: - ./server/controllers/user.js:286 + ./server/controllers/user.js:300

    @@ -952,7 +956,7 @@

    源码位置: - ./server/controllers/user.js:315 + ./server/controllers/user.js:328

    @@ -1014,7 +1018,7 @@

    源码位置: - ./server/controllers/user.js:350 + ./server/controllers/user.js:366

    @@ -1076,7 +1080,7 @@

    源码位置: - ./server/controllers/user.js:377 + ./server/controllers/user.js:397

    @@ -1168,7 +1172,7 @@

    源码位置: - ./server/controllers/user.js:426 + ./server/controllers/user.js:456

    @@ -1226,6 +1230,94 @@ } +
    + +
    +
    + +
    +

    + 描述: + 根据路由id获取面包屑数据 +

    + +

    + 源码位置: + ./server/controllers/user.js:502 +

    + + +

    + 参数: +

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数名类型描述必选支持版本
    typeString可选group|interface|project + + + +
    idNumber + + + +
    +
    + + +
    示例:
    +
    {
    +    "errcode": 0,
    +    "errmsg": "success",
    +    "data": {
    +        "interface_id": 2746,
    +        "interface_name": "/a/c",
    +        "project_id": 2481,
    +        "project_name": "www.xxx.com/api",
    +        "group_id": 181,
    +        "group_name": "YMFE"
    +    }
    +}
    + +
    @@ -1249,7 +1341,7 @@

    源码位置: - ./server/controllers/project.js:42 + ./server/controllers/project.js:34

    @@ -1390,7 +1482,7 @@

    源码位置: - ./server/controllers/project.js:114 + ./server/controllers/project.js:115

    @@ -1474,7 +1566,7 @@

    源码位置: - ./server/controllers/project.js:146 + ./server/controllers/project.js:147

    @@ -1558,7 +1650,7 @@

    源码位置: - ./server/controllers/project.js:179 + ./server/controllers/project.js:180

    @@ -1636,7 +1728,7 @@

    源码位置: - ./server/controllers/project.js:207 + ./server/controllers/project.js:208

    @@ -1719,7 +1811,7 @@

    源码位置: - ./server/controllers/project.js:231 + ./server/controllers/project.js:232

    @@ -2198,7 +2290,7 @@

    源码位置: - ./server/controllers/project.js:394 + ./server/controllers/project.js:402

    @@ -2607,7 +2699,7 @@

    源码位置: - ./server/controllers/interface.js:81 + ./server/controllers/interface.js:99

    @@ -2672,7 +2764,7 @@

    源码位置: - ./server/controllers/interface.js:104 + ./server/controllers/interface.js:124

    @@ -2737,7 +2829,7 @@

    源码位置: - ./server/controllers/interface.js:128 + ./server/controllers/interface.js:149

    @@ -2970,7 +3062,7 @@

    源码位置: - ./server/controllers/interface.js:197 + ./server/controllers/interface.js:250

    diff --git a/doc/build/index.html b/doc/build/index.html index cbe82bfb..096be711 100644 --- a/doc/build/index.html +++ b/doc/build/index.html @@ -58,8 +58,46 @@
    -

    Yapi是一个高效,易用,功能强大的api管理系统 #

    后台server如何启动和热更新? #

      -
    1. npm install
    2. npm run dev-server
    +

    YApi #

    平台介绍 #

    YApi是高效、易用、功能强大的api管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。可以帮助开发者轻松创建、发布、维护、监控和保护任意规模的 API,而且yapi为用户提供了优秀的交互体验,开发人员只需利用平台提供的接口数据写入工具以及简单的点击操作就可以实现接口的创建。

    +

    功能 #

      +
    1. 项目接口管理

      +

      提供基本的项目分组,项目管理,接口管理功能

      +
    2. mockServer服务

      +

      用户只需在项目配置线上域名和接口基本路径,通过将线上域名指到我们的yapi平台服务器,就可使用mockServer服务

      +
    3. 用户管理

      +

      提供基本的用户注册登录管理等功能,集成了去哪儿QSSO登录

      +
    +

    快速开始 #

    1 接口管理架构 #

    平台以项目分组 -> 项目 -> 接口的划分进行接口组织管理。

    +

    +

    1.1 项目分组 #

    登录之后进到项目首页,左边侧边栏显示的即分组列表。

    +

    分组列表

    +

    管理员有权限添加或删除分组。 +添加分组

    +
    +

    分组名称具有唯一性

    +
    +

    1.2 项目 #

    选中不同的分组,右边会显示该分组下的项目列表。

    +

    项目列表

    +

    创建项目需要填写项目名称,项目线上域名(添加完成后可配置项目其他环境域名),项目接口基本路径(接口路径前面相同的部分)以及项目描述。 +创建项目

    +
    +

    项目『线上域名 + 基本路径』具有唯一性

    +
    +

    1.3 接口 #

    点击项目名称,进入该项目接口列表。 +接口列表

    +

    点击编辑,进入接口详情页(之后接口详情页和编辑也会分开),可以编辑接口或者请求测试真实接口。

    +

    接口详情

    +

    请求真实接口

    +

    Mock功能 #

      yapi的Mock功能可以根据用户的输入接口信息如协议、URL、接口名、请求头、请求参数、mock规则生成Mock接口,这些接口会自动生成模拟数据,支持复杂的生成逻辑,创建者可以自由构造需要的数据。而且与常见的Mock方式如将Mock写在代码里和JS拦截等相比yapi的Mock在使用场景和效率和复杂度上是相差甚远的,正是由于yapi的Mock是一个第三方平台那么在 团队开发时任何人都可以权限许可下创建、修改接口信息等操作,这对于团队开发是很有好处的。

    +
    第一步:添加接口 #

    通过点击页面上的"+添加接口"

    +

    接口添加

    +
    第二步:输入协议、URL、接口名、请求头、请求参数、mock规则等信息,然后点击右上角的"Mock"按钮。 #

    接口详情

    +
    第三步:当点击"Mock"按钮之后,就会在页面下方生成一个mock结果并产生一个API接口。点击"复制"按钮即可复制,用户拿到接口后就可以发请求了。 #

    Mock结果

    +
    第四步:当拿到复制好接口之后就可以发起一个请求了,先将请求的信息填写完善如:请求方法(post、get等)、URL、请求头、请求的数据等。然后就点击"发送",然后在"返回结果"出可以看到接口返回的数据。 #

    请求接口

    +

    你也可以通过点击"管理成员"来添加和删除项目的成员,便于团队管理。

    +

    成员管理

    +

    未来计划推出功能 #

      +
    1. 可视化JSON编辑器,可定义JSON_Schema和mockjs
    2. 支持HTTP和RPC协议
    3. 自动化测试
    4. 多人协作
    diff --git a/doc/build/static/server/controllers/base.js.html b/doc/build/static/server/controllers/base.js.html index 5bd0eea3..6a7a4f66 100644 --- a/doc/build/static/server/controllers/base.js.html +++ b/doc/build/static/server/controllers/base.js.html @@ -25,23 +25,22 @@
    -                import yapi from '../yapi.js'
    -import  projectModel from '../models/project.js'
    -import userModel from '../models/user.js'
    +                import yapi from '../yapi.js';
    +import projectModel from '../models/project.js';
    +import userModel from '../models/user.js';
     const jwt = require('jsonwebtoken');
     
    -
    -class baseController{
    -    constructor(ctx){
    +class baseController {
    +    constructor(ctx) {
             this.ctx = ctx;
             //网站上线后,role对象key是不能修改的,value可以修改
             this.roles = {
                 admin: 'Admin',
                 member: '网站会员'
    -        }
    +        };
         }
     
    -    async init(ctx){
    +    async init(ctx) {
             this.$user = null;
             let ignoreRouter = [
                 '/user/login_by_token',
    @@ -49,76 +48,98 @@ class baseController{
                 '/user/reg',
                 '/user/status',
                 '/user/logout'
    -        ]
    -        if(ignoreRouter.indexOf(ctx.path) > -1){
    +        ];
    +        if (ignoreRouter.indexOf(ctx.path) > -1) {
                 this.$auth = true;
    -        }else{
    -            await this.checkLogin(ctx)
    +        } else {
    +            await this.checkLogin(ctx);
             }
    -        
    +
         }
     
    -    getUid(ctx){
    -        return this.$uid;
    +    getUid() {
    +        return parseInt(this.$uid, 10);
         }
     
    -    async checkLogin(ctx){
    +    async checkLogin(ctx) {
             let token = ctx.cookies.get('_yapi_token');
    -        let uid   = ctx.cookies.get('_yapi_uid');
    -        try{
    -            if(!token || !uid) return false;
    +        let uid = ctx.cookies.get('_yapi_uid');
    +
    +        try {
    +            if (!token || !uid) return false;
                 let userInst = yapi.getInst(userModel); //创建user实体
                 let result = await userInst.findById(uid);
    -            let decoded = jwt.verify(token, result.passsalt)
    -            if(decoded.uid == uid){
    +            let decoded = jwt.verify(token, result.passsalt);
    +
    +            if (decoded.uid == uid) {
                     this.$uid = uid;
                     this.$auth = true;
    -                this.$user = result;             
    +                this.$user = result;
                     return true;
                 }
    +
                 return false;
    -        }catch(e){
    +        } catch (e) {
                 return false;
             }
     
         }
     
    -    async getLoginStatus(ctx){
    -        if(await this.checkLogin(ctx) === true){            
    -            return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user,['_id','username','email', 'up_time', 'add_time']));
    +    async getLoginStatus(ctx) {
    +        if (await this.checkLogin(ctx) === true) {
    +            let result = yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time']);
    +            result.server_ip = yapi.WEBCONFIG.server_ip;
    +            return ctx.body = yapi.commons.resReturn(result);
             }
    -        return ctx.body = yapi.commons.resReturn(null, 300 , 'Please login.');
    -
    +        return ctx.body = yapi.commons.resReturn(null, 300, 'Please login.');
         }
     
    -    getRole(){
    +    getRole() {
             return this.$user.role;
         }
     
    -    async jungeProjectAuth(id){
    +    async jungeProjectAuth(id) {
             let model = yapi.getInst(projectModel);
    -        if(this.getRole() === 'admin') return true;
    -        if(!id) return false;
    -        let result =  await model.get(id);
    -        if(result.uid === this.getUid()){
    +
    +        if (this.getRole() === 'admin') {
                 return true;
             }
    +
    +        if (!id) {
    +            return false;
    +        }
    +
    +        let result = await model.get(id);
    +
    +        if (result.uid === this.getUid()) {
    +            return true;
    +        }
    +
             return false;
         }
     
    -    async jungeMemberAuth(id, member_uid){
    +    async jungeMemberAuth(id, member_uid) {
             let model = yapi.getInst(projectModel);
    -        if(this.getRole() === 'admin') return true;
    -        if(!id || !member_uid) return false;
    -        let result =  await model.checkMemberRepeat(id, member_uid);
    -        if(result > 0){
    +
    +        if (this.getRole() === 'admin') {
                 return true;
             }
    +
    +        if (!id || !member_uid) {
    +            return false;
    +        }
    +
    +        let result = await model.checkMemberRepeat(id, member_uid);
    +
    +        if (result > 0) {
    +            return true;
    +        }
    +
             return false;
         }
     }
     
    -module.exports = baseController
    +module.exports = baseController;
                     
    diff --git a/doc/build/static/server/controllers/group.js.html b/doc/build/static/server/controllers/group.js.html index e0ce4751..7f253f79 100644 --- a/doc/build/static/server/controllers/group.js.html +++ b/doc/build/static/server/controllers/group.js.html @@ -25,17 +25,15 @@
    -                import  groupModel from '../models/group.js'
    -import yapi from '../yapi.js'
    -import baseController from './base.js'
    -import  projectModel from '../models/project.js'
    +                import groupModel from '../models/group.js';
    +import yapi from '../yapi.js';
    +import baseController from './base.js';
    +import projectModel from '../models/project.js';
     
    -// 
    -class groupController extends baseController{
    -    constructor(ctx){
    -        super(ctx)
    +class groupController extends baseController {
    +    constructor(ctx) {
    +        super(ctx);
         }
    -  
     
         /**
          * 添加项目分组
    @@ -50,33 +48,45 @@ class groupController extends baseController{
          */
         async add(ctx) {
             let params = ctx.request.body;
    -        if(this.getRole() !== 'admin'){
    -            return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
    +
    +        params = yapi.commons.handleParams(params, {
    +            group_name: 'string',
    +            group_desc: 'string'
    +        });
    +
    +        if (this.getRole() !== 'admin') {
    +            return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
             }
    -        if(!params.group_name){
    +
    +        if (!params.group_name) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目分组名不能为空');
             }
    -        var groupInst = yapi.getInst(groupModel);
    -        
    -        var checkRepeat = await groupInst.checkRepeat(params.group_name);
    -        if(checkRepeat > 0){
    -            return ctx.body =  yapi.commons.resReturn(null, 401, '项目分组名已存在');
    +
    +        let groupInst = yapi.getInst(groupModel);
    +
    +        let checkRepeat = await groupInst.checkRepeat(params.group_name);
    +
    +        if (checkRepeat > 0) {
    +            return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在');
             }
    +
             let data = {
                 group_name: params.group_name,
                 group_desc: params.group_desc,
    -            uid: '0',
    +            uid: this.getUid(),
                 add_time: yapi.commons.time(),
                 up_time: yapi.commons.time()
    -        }
    -        try{
    +        };
    +
    +        try {
                 let result = await groupInst.save(data);
    +
                 result = yapi.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
                 ctx.body = yapi.commons.resReturn(result);
    -        }catch(e){
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
    -        
    +
         }
     
         /**
    @@ -88,14 +98,13 @@ class groupController extends baseController{
          * @returns {Object} 
          * @example ./api/group/list.json
          */
    -
         async list(ctx) {
    -        try{
    +        try {
                 var groupInst = yapi.getInst(groupModel);
                 let result = await groupInst.list();
    -            ctx.body = yapi.commons.resReturn(result)
    -        }catch(e){
    -             ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            ctx.body = yapi.commons.resReturn(result);
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
         }
     
    @@ -109,27 +118,30 @@ class groupController extends baseController{
          * @returns {Object} 
          * @example ./api/group/del.json
          */
    +    async del(ctx) {
    +        if (this.getRole() !== 'admin') {
    +            return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
    +        }
     
    -    async del(ctx){
    -        if(this.getRole() !== 'admin'){
    -            return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
    -        }   
    -        try{
    -            var groupInst = yapi.getInst(groupModel);
    -            var projectInst = yapi.getInst(projectModel);
    -            let id = ctx.request.body.id;            
    -            if(!id){
    +        try {
    +            let groupInst = yapi.getInst(groupModel);
    +            let projectInst = yapi.getInst(projectModel);
    +            let id = ctx.request.body.id;
    +
    +            if (!id) {
                     return ctx.body = yapi.commons.resReturn(null, 402, 'id不能为空');
                 }
    -            let count = await  projectInst.countByGroupId(id);
    -            if(count > 0){
    +
    +            let count = await projectInst.countByGroupId(id);
    +
    +            if (count > 0) {
                     return ctx.body = yapi.commons.resReturn(null, 403, '请先删除该分组下的项目');
                 }
     
                 let result = await groupInst.del(id);
    -            ctx.body = yapi.commons.resReturn(result)
    -        }catch(err){
    -             ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            ctx.body = yapi.commons.resReturn(result);
    +        } catch (err) {
    +            ctx.body = yapi.commons.resReturn(null, 402, err.message);
             }
         }
     
    @@ -145,31 +157,35 @@ class groupController extends baseController{
          * @returns {Object} 
          * @example ./api/group/up.json
          */
    -
    -    async up(ctx){
    -        if(this.getRole() !== 'admin'){
    -            return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
    +    async up(ctx) {
    +        if (this.getRole() !== 'admin') {
    +            return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
             }
    -        try{
    -            var groupInst = yapi.getInst(groupModel);
    +
    +        try {
    +
    +            ctx.request.body = yapi.commons.handleParams(ctx.request.body, {
    +                id: 'number',
    +                group_name: 'string',
    +                group_desc: 'string'
    +            });
    +            let groupInst = yapi.getInst(groupModel);
                 let id = ctx.request.body.id;
                 let data = {};
    -            ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name)
    -            ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc)
    -            if(Object.keys(data).length === 0 ){
    +            ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name);
    +            ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc);
    +            if (Object.keys(data).length === 0) {
                     ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述不能为空');
                 }
                 let result = await groupInst.up(id, data);
    -            ctx.body = yapi.commons.resReturn(result)
    -        }catch(err){
    -             ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            ctx.body = yapi.commons.resReturn(result);
    +        } catch (err) {
    +            ctx.body = yapi.commons.resReturn(null, 402, err.message);
             }
         }
     }
     
    -
    -module.exports = groupController
    -
    +module.exports = groupController;
                     
    diff --git a/doc/build/static/server/controllers/interface.js.html b/doc/build/static/server/controllers/interface.js.html index 4f72041e..4ce1d505 100644 --- a/doc/build/static/server/controllers/interface.js.html +++ b/doc/build/static/server/controllers/interface.js.html @@ -25,13 +25,13 @@
    -                import interfaceModel from '../models/interface.js'
    -import baseController from './base.js'
    -import yapi from '../yapi.js'
    +                import interfaceModel from '../models/interface.js';
    +import baseController from './base.js';
    +import yapi from '../yapi.js';
     
    -class interfaceController extends baseController{
    -    constructor(ctx){
    -        super(ctx)
    +class interfaceController extends baseController {
    +    constructor(ctx) {
    +        super(ctx);
             this.Model = yapi.getInst(interfaceModel);
         }
     
    @@ -62,25 +62,39 @@ class interfaceController extends baseController{
          * @returns {Object} 
          * @example ./api/interface/add.json
          */
    -    async add(ctx){
    +    async add(ctx) {
             let params = ctx.request.body;
    +
    +        params = yapi.commons.handleParams(params, {
    +            project_id: 'number',
    +            title: 'string',
    +            path: 'string',
    +            method: 'string',
    +            desc: 'string'
    +        });
             params.method = params.method || 'GET';
    -        params.method = params.method.toUpperCase()
    +        params.method = params.method.toUpperCase();
             params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
    -        if(!params.project_id){
    +
    +        if (!params.project_id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
             }
     
    -        if(!params.path){
    +        if (!params.path) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '接口请求路径不能为空');
             }
     
    -        let checkRepeat = await this.Model.checkRepeat(params.path, params.method);
    -        if(checkRepeat > 0){
    -            return ctx.body =  yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
    -        }       
    +        if (!yapi.commons.verifyPath(params.path)) {
    +            return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
    +        }
     
    -        try{
    +        let checkRepeat = await this.Model.checkRepeat(params.project_id, params.path, params.method);
    +
    +        if (checkRepeat > 0) {
    +            return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
    +        }
    +
    +        try {
                 let data = {
                     project_id: params.project_id,
                     title: params.title,
    @@ -89,20 +103,24 @@ class interfaceController extends baseController{
                     method: params.method,
                     req_headers: params.req_headers,
                     req_params_type: params.req_params_type,
    -                res_body:  params.res_body,
    +                res_body: params.res_body,
                     res_body_type: params.res_body_type,
                     uid: this.getUid(),
                     add_time: yapi.commons.time(),
                     up_time: yapi.commons.time()
    +            };
    +
    +            if (params.req_params_form) {
    +                data.req_params_form = params.req_params_form;
    +            }
    +            if (params.req_params_other) {
    +                data.req_params_other = params.req_params_other;
                 }
     
    -            if(params.req_params_form) data.req_params_form = params.req_params_form;
    -            if(params.req_params_other) data.req_params_other = params.req_params_other;
    -            
                 let result = await this.Model.save(data);
                 ctx.body = yapi.commons.resReturn(result);
    -        }catch(e){
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
         }
     
    @@ -116,16 +134,18 @@ class interfaceController extends baseController{
          * @returns {Object} 
          * @example ./api/interface/get.json
          */
    -    async get(ctx){
    +    async get(ctx) {
             let params = ctx.request.query;
    -        if(!params.id){
    +
    +        if (!params.id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
             }
    -        try{
    +
    +        try {
                 let result = await this.Model.get(params.id);
                 ctx.body = yapi.commons.resReturn(result);
    -        }catch(e){
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
         }
     
    @@ -139,17 +159,18 @@ class interfaceController extends baseController{
          * @returns {Object} 
          * @example ./api/interface/list.json
          */
    -
    -    async list(ctx){
    +    async list(ctx) {
             let project_id = ctx.request.query.project_id;
    -        if(!project_id){
    +
    +        if (!project_id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
             }
    -        try{
    +
    +        try {
                 let result = await this.Model.list(project_id);
    -            ctx.body = yapi.commons.resReturn(result)
    -        }catch(err){
    -             ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            ctx.body = yapi.commons.resReturn(result);
    +        } catch (err) {
    +            ctx.body = yapi.commons.resReturn(null, 402, err.message);
             }
         }
     
    @@ -180,44 +201,76 @@ class interfaceController extends baseController{
          * @example ./api/interface/up.json
          */
     
    -    async up(ctx){
    +    async up(ctx) {
             let params = ctx.request.body;
    +
    +        params = yapi.commons.handleParams(params, {
    +            title: 'string',
    +            path: 'string',
    +            method: 'string',
    +            desc: 'string'
    +        });
             params.method = params.method || 'GET';
    -        params.method = params.method.toUpperCase()
    +        params.method = params.method.toUpperCase();
    +
             let id = ctx.request.body.id;
    -        if(!id){
    +        
    +        if (!id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
             }
             let interfaceData = await this.Model.get(id);
    -        if(params.path && params.path !== interfaceData.path  && params.method !== interfaceData.method){
    -            let checkRepeat = await this.Model.checkRepeat(params.path, params.method);
    -            if(checkRepeat > 0){
    -                return ctx.body =  yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
    +
    +        if (params.path && !yapi.commons.verifyPath(params.path)) {
    +            return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
    +        }
    +
    +        if (params.path && params.path !== interfaceData.path && params.method !== interfaceData.method) {
    +            let checkRepeat = await this.Model.checkRepeat(interfaceData.project_id, params.path, params.method);
    +            if (checkRepeat > 0) {
    +                return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
                 }
    -        }       
    +        }
     
             let data = {
                 up_time: yapi.commons.time()
    +        };
    +
    +        if (params.path) {
    +            data.path = params.path;
    +        }
    +        if (params.title) {
    +            data.title = params.title;
    +        }
    +        if (params.desc) {
    +            data.desc = params.desc;
    +        }
    +        if (params.method) {
    +            data.method = params.method;
             }
     
    -        if(params.path) data.path = params.path;
    -        if(params.title) data.title = params.title;
    -        if(params.desc) data.desc = params.desc;
    -        if(params.method) data.method = params.method;
    +        if (params.req_headers) {
    +            data.req_headers = params.req_headers;
    +        }
     
    -        if(params.req_headers) data.req_headers = params.req_headers;
    +        if (params.req_params_form) {
    +            data.req_params_form = params.req_params_form;
    +        }
    +        if (params.req_params_other) {
    +            data.req_params_other = params.req_params_other;
    +        }
     
    -        if(params.req_params_form) data.req_params_form = params.req_params_form;
    -        if(params.req_params_other) data.req_params_other = params.req_params_other;
    -        
    -        if(params.res_body_type) data.res_body_type = params.res_body_type;
    -        if(params.res_body) data.res_body = params.res_body;
    +        if (params.res_body_type) {
    +            data.res_body_type = params.res_body_type;
    +        }
    +        if (params.res_body) {
    +            data.res_body = params.res_body;
    +        }
     
    -        try{
    +        try {
                 let result = await this.Model.up(id, data);
    -            ctx.body = yapi.commons.resReturn(result)
    -        }catch(e){
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            ctx.body = yapi.commons.resReturn(result);
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
     
         }
    @@ -233,27 +286,27 @@ class interfaceController extends baseController{
          * @example ./api/interface/del.json
          */
     
    -    async del(ctx){
    -        try{
    -            let id = ctx.request.body.id;            
    -            
    -            if(!id){
    +    async del(ctx) {
    +        try {
    +            let id = ctx.request.body.id;
    +
    +            if (!id) {
                     return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
                 }
     
    -            let data = await this.Model.get(params.id);
    +            let data = await this.Model.get(ctx.request.body.id);
     
    -            if(data.uid != this.getUid()){
    -                if(await this.jungeProjectAuth(data.project_id) !== true){
    +            if (data.uid != this.getUid()) {
    +                if (await this.jungeProjectAuth(data.project_id) !== true) {
                         return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
                     }
                 }
     
    -            
    +
                 let result = await this.Model.del(id);
    -            ctx.body = yapi.commons.resReturn(result)
    -        }catch(err){
    -             ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            ctx.body = yapi.commons.resReturn(result);
    +        } catch (err) {
    +            ctx.body = yapi.commons.resReturn(null, 402, err.message);
             }
         }
     }
    diff --git a/doc/build/static/server/controllers/log.js.html b/doc/build/static/server/controllers/log.js.html
    index 8b97b845..a2e08e0f 100644
    --- a/doc/build/static/server/controllers/log.js.html
    +++ b/doc/build/static/server/controllers/log.js.html
    @@ -55,19 +55,20 @@ class logController extends baseController {
                 page = ctx.request.query.page || 1,
                 limit = ctx.request.query.limit || 10;
     
    -        if(!uid){
    +        if (!uid) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '用户id不能为空');
             }
     
             try {
                 let result = await this.Model.listWithPaging(uid, page, limit);
                 let count = await this.Model.listCount(uid);
    +            
                 ctx.body = yapi.commons.resReturn({
                     total: Math.ceil(count / limit),
                     list: result
    -            })
    -        } catch(err) {
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            });
    +        } catch (err) {
    +            ctx.body = yapi.commons.resReturn(null, 402, err.message);
             }
         }
     
    diff --git a/doc/build/static/server/controllers/project.js.html b/doc/build/static/server/controllers/project.js.html
    index 08d098b3..4fc6c6ec 100644
    --- a/doc/build/static/server/controllers/project.js.html
    +++ b/doc/build/static/server/controllers/project.js.html
    @@ -25,43 +25,35 @@
                 
    -                import projectModel from '../models/project.js'
    -import yapi from '../yapi.js'
    -import baseController from './base.js'
    -import interfaceModel from '../models/interface.js'
    -import groupModel from '../models/group'
    -import commons from '../utils/commons.js'
    -import userModel from '../models/user.js'
    +                import projectModel from '../models/project.js';
    +import yapi from '../yapi.js';
    +import baseController from './base.js';
    +import interfaceModel from '../models/interface.js';
    +import groupModel from '../models/group';
    +import commons from '../utils/commons.js';
    +import userModel from '../models/user.js';
     
     class projectController extends baseController {
     
    -    constructor(ctx){
    -        super(ctx)
    +    constructor(ctx) {
    +        super(ctx);
             this.Model = yapi.getInst(projectModel);
             this.groupModel = yapi.getInst(groupModel);
         }
     
    -    handleBasepath(basepath){
    -        if(!basepath) return false;
    -        if(basepath[0] !== '/') basepath = '/' + basepath;
    -        if(basepath[basepath.length -1] === '/') basepath = basepath.substr(0, basepath.length -1)
    -        if(!this.verifyPath(basepath)){
    +    handleBasepath(basepath) {
    +        if (!basepath) return false;
    +        if (basepath[0] !== '/') basepath = '/' + basepath;
    +        if (basepath[basepath.length - 1] === '/') basepath = basepath.substr(0, basepath.length - 1);
    +        if (!yapi.commons.verifyPath(basepath)) {
                 return false;
             }
             return basepath;
         }
     
    -    verifyPath(path){
    -        if(/^[a-zA-Z0-9\-\/_:]+$/.test(path)){
    -            return true;
    -        }else{
    -            return false;
    -        }
    -    }
    -
    -    verifyDomain(domain){
    -        if(!domain) return false;
    -        if(/^[a-zA-Z0-9\-_\.]+[a-zA-Z]{2,6}$/.test(domain)){
    +    verifyDomain(domain) {
    +        if (!domain) return false;
    +        if (/^[a-zA-Z0-9\-_\.]+?\.[a-zA-Z0-9\-_\.]*?[a-zA-Z]{2,6}$/.test(domain)) {
                 return true;
             }
             return false;
    @@ -78,46 +70,55 @@ class projectController extends baseController {
          * @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
          * @param {String} protocol 线上域名协议,不能为空
          * @param {Number} group_id 项目分组id,不能为空
    -     * @param  {String} [desc] 项目描述 
    -     * @returns {Object} 
    +     * @param  {String} [desc] 项目描述
    +     * @returns {Object}
          * @example ./api/project/add.json
          */
         async add(ctx) {
             let params = ctx.request.body;
    -
    -        if(!params.group_id){
    +        params = yapi.commons.handleParams(params, {
    +            name: 'string',
    +            basepath: 'string',
    +            prd_host: 'string',
    +            protocol: 'string',
    +            group_id: 'number',
    +            desc: 'string'
    +        });
    +        if (!params.group_id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
             }
     
    -        if(!params.name){
    +        if (!params.name) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目名不能为空');
             }
     
             let checkRepeat = await this.Model.checkNameRepeat(params.name);
    -        if(checkRepeat > 0){
    -            return ctx.body =  yapi.commons.resReturn(null, 401, '已存在的项目名');
    +
    +        if (checkRepeat > 0) {
    +            return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
             }
     
    -        if(!params.basepath){
    +        if (!params.basepath) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目basepath不能为空');
             }
    -        if(!params.prd_host){
    +        if (!params.prd_host) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
             }
     
    -        if((params.basepath = this.handleBasepath(params.basepath)) === false){
    -            return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
    +        if ((params.basepath = this.handleBasepath(params.basepath)) === false) {
    +            return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误');
             }
     
    -        if(!this.verifyDomain(params.prd_host)){
    -            return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误')
    +        if (!this.verifyDomain(params.prd_host)) {
    +            return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误');
             }
     
             let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
    -        if(checkRepeatDomain > 0){
    -            return ctx.body =  yapi.commons.resReturn(null, 401, '已存在domain和basepath');
    +
    +        if (checkRepeatDomain > 0) {
    +            return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
             }
    -        
    +
             let data = {
                 name: params.name,
                 desc: params.desc,
    @@ -129,78 +130,78 @@ class projectController extends baseController {
                 group_id: params.group_id,
                 add_time: yapi.commons.time(),
                 up_time: yapi.commons.time()
    +        };
    +
    +        try {
    +            let result = await this.Model.save(data);
    +            ctx.body = yapi.commons.resReturn(result);
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
     
    -        try{
    -            let result = await this.Model.save(data);           
    -            ctx.body = yapi.commons.resReturn(result);
    -        }catch(e){
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    -        }
    -        
         }
    -     /**
    -     * 添加项目
    -     * @interface /project/add_member
    -     * @method POST
    -     * @category project
    -     * @foldnumber 10
    -     * @param {Number} id 项目id,不能为空
    -     * @param {String} member_uid 项目成员uid,不能为空
    -     * @returns {Object} 
    -     * @example ./api/project/add_member.json
    -     */
    -    async addMember(ctx){
    +    /**
    +    * 添加项目
    +    * @interface /project/add_member
    +    * @method POST
    +    * @category project
    +    * @foldnumber 10
    +    * @param {Number} id 项目id,不能为空
    +    * @param {String} member_uid 项目成员uid,不能为空
    +    * @returns {Object}
    +    * @example ./api/project/add_member.json
    +    */
    +    async addMember(ctx) {
             let params = ctx.request.body;
    -        if(!params.member_uid){
    +        if (!params.member_uid) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目成员uid不能为空');
             }
    -        if(!params.id){
    +        if (!params.id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
             }
     
             var check = await this.Model.checkMemberRepeat(params.id, params.member_uid);
    -        if(check > 0){
    -             return ctx.body = yapi.commons.resReturn(null, 400, '项目成员已存在');
    +        if (check > 0) {
    +            return ctx.body = yapi.commons.resReturn(null, 400, '项目成员已存在');
             }
    -        try{
    +        try {
                 let result = await this.Model.addMember(params.id, params.member_uid);
                 ctx.body = yapi.commons.resReturn(result);
    -        }catch(e){
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
     
         }
    -     /**
    -     * 添加项目
    -     * @interface /project/del_member
    -     * @method POST
    -     * @category project
    -     * @foldnumber 10
    -     * @param {Number} id 项目id,不能为空
    -     * @param {member_uid} uid 项目成员uid,不能为空
    -     * @returns {Object} 
    -     * @example ./api/project/del_member.json
    -     */
    +    /**
    +    * 添加项目
    +    * @interface /project/del_member
    +    * @method POST
    +    * @category project
    +    * @foldnumber 10
    +    * @param {Number} id 项目id,不能为空
    +    * @param {member_uid} uid 项目成员uid,不能为空
    +    * @returns {Object}
    +    * @example ./api/project/del_member.json
    +    */
     
    -    async delMember(ctx){
    +    async delMember(ctx) {
             let params = ctx.request.body;
    -        if(!params.member_uid){
    +        if (!params.member_uid) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目成员uid不能为空');
             }
    -        if(!params.id){
    +        if (!params.id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
             }
             var check = await this.Model.checkMemberRepeat(params.id, params.member_uid);
    -        if(check === 0){
    -             return ctx.body = yapi.commons.resReturn(null, 400, '项目成员不存在');
    +        if (check === 0) {
    +            return ctx.body = yapi.commons.resReturn(null, 400, '项目成员不存在');
             }
     
    -         try{
    +        try {
                 let result = await this.Model.delMember(params.id, params.member_uid);
                 ctx.body = yapi.commons.resReturn(result);
    -        }catch(e){
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
         }
     
    @@ -217,7 +218,7 @@ class projectController extends baseController {
     
         async getMemberList(ctx) {
             let params = ctx.request.query;
    -        if(!params.id) {
    +        if (!params.id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
             }
     
    @@ -227,32 +228,32 @@ class projectController extends baseController {
                 let result = await userInst.findByUids(project.members);
     
                 ctx.body = yapi.commons.resReturn(result);
    -        } catch(e) {
    +        } catch (e) {
                 ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
         }
     
    -     /**
    -     * 添加项目
    -     * @interface /project/get
    -     * @method GET
    -     * @category project
    -     * @foldnumber 10
    -     * @param {Number} id 项目id,不能为空
    -     * @returns {Object} 
    -     * @example ./api/project/get.json
    -     */
    +    /**
    +    * 添加项目
    +    * @interface /project/get
    +    * @method GET
    +    * @category project
    +    * @foldnumber 10
    +    * @param {Number} id 项目id,不能为空
    +    * @returns {Object}
    +    * @example ./api/project/get.json
    +    */
     
    -    async get(ctx){
    +    async get(ctx) {
             let params = ctx.request.query;
    -        if(!params.id){
    +        if (!params.id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
             }
    -        try{
    +        try {
                 let result = await this.Model.get(params.id);
                 ctx.body = yapi.commons.resReturn(result);
    -        }catch(e){
    -            ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
         }
     
    @@ -265,7 +266,7 @@ class projectController extends baseController {
          * @param {Number} group_id 项目group_id,不能为空
          * @param {Number} [page] 分页页码
          * @param {Number} [limit] 每页数据条目,默认为10
    -     * @returns {Object} 
    +     * @returns {Object}
          * @example ./api/project/list.json
          */
     
    @@ -274,32 +275,31 @@ class projectController extends baseController {
                 page = ctx.request.query.page || 1,
                 limit = ctx.request.query.limit || 10;
     
    -        if(!group_id){
    +        if (!group_id) {
                 return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
             }
     
    -        try{
    +        try {
                 let result = await this.Model.listWithPaging(group_id, page, limit);
                 let count = await this.Model.listCount(group_id);
                 let uids = [];
    -            result.forEach( (item)=> {
    -                if(uids.indexOf(item.uid) !== -1){
    -                    uids.push(item.uid)
    +            result.forEach((item) => {
    +                if (uids.indexOf(item.uid) === -1) {
    +                    uids.push(item.uid);
                     }
    -                
    -            } )
     
    +            });
                 let _users = {}, users = await yapi.getInst(userModel).findByUids(uids);
    -            users.forEach((item)=> {
    +            users.forEach((item) => {
                     _users[item._id] = item;
    -            } )
    +            });
                 ctx.body = yapi.commons.resReturn({
                     total: Math.ceil(count / limit),
                     list: result,
                     userinfo: _users
    -            })
    -        }catch(err){
    -             ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            });
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
         }
     
    @@ -310,29 +310,29 @@ class projectController extends baseController {
          * @category project
          * @foldnumber 10
          * @param {Number} id 项目id,不能为空
    -     * @returns {Object} 
    +     * @returns {Object}
          * @example ./api/project/del.json
          */
     
    -    async del(ctx){   
    -        try{
    +    async del(ctx) {
    +        try {
                 let id = ctx.request.body.id;
    -            if(!id){
    +            if (!id) {
                     return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
                 }
                 let interfaceInst = yapi.getInst(interfaceModel);
                 let count = await interfaceInst.countByProjectId(id);
    -            if(count > 0){
    +            if (count > 0) {
                     return ctx.body = yapi.commons.resReturn(null, 400, '请先删除该项目下所有接口');
                 }
     
    -            if(await this.jungeProjectAuth(id) !== true){
    +            if (await this.jungeProjectAuth(id) !== true) {
                     return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
                 }
                 let result = await this.Model.del(id);
                 ctx.body = yapi.commons.resReturn(result);
    -        }catch(err){
    -             ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +        } catch (err) {
    +            ctx.body = yapi.commons.resReturn(null, 402, err.message);
             }
         }
     
    @@ -346,76 +346,84 @@ class projectController extends baseController {
          * @param {String} name 项目名称,不能为空
          * @param {String} basepath 项目基本路径,不能为空
          * @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
    -     * @param {String} [desc] 项目描述 
    +     * @param {String} [desc] 项目描述
          * @param {Array} [env] 项目环境配置
          * @param {String} [env[].name] 环境名称
          * @param {String} [env[].domain] 环境域名
    -     * @returns {Object} 
    +     * @returns {Object}
          * @example ./api/project/up.json
          */
     
    -    async up(ctx){
    -        try{            
    +    async up(ctx) {
    +        try {
                 let id = ctx.request.body.id;
                 let params = ctx.request.body;
    -            if(!id){
    +            params = yapi.commons.handleParams(params, {
    +                name: 'string',
    +                basepath: 'string',
    +                prd_host: 'string',
    +                protocol: 'string',
    +                group_id: 'number',
    +                desc: 'string'
    +            });
    +            if (!id) {
                     return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
                 }
     
    -            if(await this.jungeMemberAuth(id, this.getUid()) !== true){
    +            if (await this.jungeMemberAuth(id, this.getUid()) !== true) {
                     return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
                 }
    -            
    +
                 let projectData = await this.Model.get(id);
     
    -            if(params.basepath = (this.handleBasepath(params.basepath)) === false){
    -                return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
    +            if ((params.basepath = this.handleBasepath(params.basepath)) === false) {
    +                return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误');
                 }
     
    -            if(!this.verifyDomain(params.prd_host)){
    -                return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误')
    +            if (!this.verifyDomain(params.prd_host)) {
    +                return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误');
                 }
    -            
    -            if(projectData.name === params.name){
    +
    +            if (projectData.name === params.name) {
                     delete params.name;
                 }
    -            if(projectData.basepath === params.basepath && projectData.prd_host === params.prd_host){
    -                delete params.basepath
    -                delete params.prd_host
    +            if (projectData.basepath === params.basepath && projectData.prd_host === params.prd_host) {
    +                delete params.basepath;
    +                delete params.prd_host;
                 }
     
    -            if(params.name){
    +            if (params.name) {
                     let checkRepeat = await this.Model.checkNameRepeat(params.name);
    -                if(checkRepeat > 0){
    -                    return ctx.body =  yapi.commons.resReturn(null, 401, '已存在的项目名');
    +                if (checkRepeat > 0) {
    +                    return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
                     }
                 }
     
    -            if(params.basepath && params.prd_host){
    +            if (params.basepath && params.prd_host) {
                     let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
    -                if(checkRepeatDomain > 0){
    -                    return ctx.body =  yapi.commons.resReturn(null, 401, '已存在domain和basepath');
    +                if (checkRepeatDomain > 0) {
    +                    return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
                     }
                 }
     
    -            let data= {
    +            let data = {
                     uid: this.getUid(),
                     up_time: yapi.commons.time()
    -            }
    +            };
     
    -            if(params.name) data.name = params.name;
    -            if(params.desc) data.desc = params.desc;
    -            if(params.prd_host && params.basepath){
    +            if (params.name) data.name = params.name;
    +            if (params.desc) data.desc = params.desc;
    +            if (params.prd_host && params.basepath) {
                     data.prd_host = params.prd_host;
                     data.basepath = params.basepath;
                 }
    -            if(params.protocol) data.protocol = params.protocol;
    -            if(params.env) data.env = params.env;
    +            if (params.protocol) data.protocol = params.protocol;
    +            if (params.env) data.env = params.env;
     
                 let result = await this.Model.up(id, data);
    -            ctx.body = yapi.commons.resReturn(result)
    -        }catch(e){
    -             ctx.body = yapi.commons.resReturn(null, 402, e.message)
    +            ctx.body = yapi.commons.resReturn(result);
    +        } catch (e) {
    +            ctx.body = yapi.commons.resReturn(null, 402, e.message);
             }
         }
     
    @@ -433,11 +441,11 @@ class projectController extends baseController {
             const { q } = ctx.request.query;
     
             if (!q) {
    -            return ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.')
    +            return ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.');
             }
     
             if (!yapi.commons.validateSearchKeyword(q)) {
    -            return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.')
    +            return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.');
             }
     
             let projectList = await this.Model.search(q);
    @@ -457,12 +465,12 @@ class projectController extends baseController {
             let groupRules = [
                 '_id',
                 'uid',
    -            { key: 'group_name', alias: 'groupName'},
    +            { key: 'group_name', alias: 'groupName' },
                 { key: 'group_desc', alias: 'groupDesc' },
                 { key: 'add_time', alias: 'addTime' },
                 { key: 'up_time', alias: 'upTime' }
             ];
    -        
    +
             projectList = commons.filterRes(projectList, projectRules);
             groupList = commons.filterRes(groupList, groupRules);
     
    @@ -470,12 +478,13 @@ class projectController extends baseController {
                 project: projectList,
                 group: groupList
             };
    -        
    -        return ctx.body = yapi.commons.resReturn(queryList, 0, 'ok')
    +
    +        return ctx.body = yapi.commons.resReturn(queryList, 0, 'ok');
         }
     }
     
     module.exports = projectController;
    +
                     
    diff --git a/doc/build/static/server/controllers/user.js.html b/doc/build/static/server/controllers/user.js.html index e5dd7daf..a0cffb7b 100644 --- a/doc/build/static/server/controllers/user.js.html +++ b/doc/build/static/server/controllers/user.js.html @@ -25,18 +25,21 @@
    -                import userModel from '../models/user.js'
    -import yapi from '../yapi.js'
    -import baseController from './base.js'
    -import mongoose from 'mongoose'
    -import request from 'request'
    -import common from '../utils/commons.js'
    +                import userModel from '../models/user.js';
    +import yapi from '../yapi.js';
    +import baseController from './base.js';
    +import request from 'request';
    +import common from '../utils/commons.js';
    +
    +import interfaceModel from '../models/interface.js'
    +import groupModel from '../models/group.js'
    +import projectModel from '../models/project.js'
     
     const jwt = require('jsonwebtoken');
     
     class userController extends baseController {
         constructor(ctx) {
    -        super(ctx)
    +        super(ctx);
             this.Model = yapi.getInst(userModel);
         }
         /**
    @@ -68,14 +71,15 @@ class userController extends baseController {
             if (!result) {
                 return ctx.body = yapi.commons.resReturn(null, 404, '该用户不存在');
             } else if (yapi.commons.generatePassword(password, result.passsalt) === result.password) {
    -            this.setLoginCookie(result._id, result.passsalt)
    +            this.setLoginCookie(result._id, result.passsalt);
     
                 return ctx.body = yapi.commons.resReturn({
                     username: result.username,
                     uid: result._id,
                     email: result.email,
                     add_time: result.add_time,
    -                up_time: result.up_time
    +                up_time: result.up_time,
    +                server_ip: yapi.WEBCONFIG.server_ip
     
                 }, 0, 'logout success...');
             } else {
    @@ -115,45 +119,45 @@ class userController extends baseController {
                                     let ret = {
                                         email: result.userId + '@qunar.com',
                                         username: result.data.userInfo.name
    -                                }
    -                                resolve(ret)
    +                                };
    +                                resolve(ret);
                                 } else {
    -                                reject(result)
    +                                reject(result);
                                 }
                             }
    -                        reject(error)
    -                    })
    -                })
    +                        reject(error);
    +                    });
    +                });
                 },
    -            tokenField: 'token',
    -        }
    +            tokenField: 'token'
    +        };
         }
     
    -
    -
         async loginByToken(ctx) {
             let config = this.thirdQunarLogin();
    -
             let token = ctx.request.body[config.tokenField] || ctx.request.query[config.tokenField];
     
             try {
                 let ret = await config.request(token);
                 let login = await this.handleThirdLogin(ret.email, ret.username);
    +
                 if (login === true) {
                     yapi.commons.log('login success');
    -                ctx.redirect('/')
    +                ctx.redirect('/');
                 }
             } catch (e) {
    -            yapi.commons.log(e.message, 'error')
    -            ctx.redirect('/')
    +            yapi.commons.log(e.message, 'error');
    +            ctx.redirect('/');
             }
         }
     
         async handleThirdLogin(email, username) {
             let user, data, passsalt;
    -        var userInst = yapi.getInst(userModel);
    +        let userInst = yapi.getInst(userModel);
    +
             try {
                 user = await userInst.findByEmail(email);
    +
                 if (!user || !user._id) {
                     passsalt = yapi.commons.randStr();
                     data = {
    @@ -164,14 +168,18 @@ class userController extends baseController {
                         role: 'member',
                         add_time: yapi.commons.time(),
                         up_time: yapi.commons.time()
    -                }
    +                };
                     user = await userInst.save(data);
    +                yapi.commons.sendMail({
    +                    to: email,
    +                    contents: `

    亲爱的用户:

    您好,感谢使用YApi,系统检测您是第一次用Qsso账号登录YApi服务,您的Email是: ${email} ,初始化密码为:${passsalt}

    ` + }); } - this.setLoginCookie(user._id, user.passsalt) + this.setLoginCookie(user._id, user.passsalt); return true; } catch (e) { - console.error(e.message) + console.error('third_login:', e.message); // eslint-disable-line return false; } } @@ -228,27 +236,23 @@ class userController extends baseController { } } - async forgetPassword(ctx) { + async forgetPassword() { } - } - - async resetPassword(ctx) { - - } + async resetPassword() { } setLoginCookie(uid, passsalt) { let token = jwt.sign({ uid: uid }, passsalt, { expiresIn: '7 days' }); + this.ctx.cookies.set('_yapi_token', token, { expires: yapi.commons.expireDate(7), httpOnly: true - }) + }); this.ctx.cookies.set('_yapi_uid', uid, { expires: yapi.commons.expireDate(7), httpOnly: true - }) + }); } - /** * 用户注册接口 * @interface /user/reg @@ -262,16 +266,25 @@ class userController extends baseController { * @example ./api/user/login.json */ async reg(ctx) { //注册 - var userInst = yapi.getInst(userModel); + let userInst = yapi.getInst(userModel); let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码 + + params = yapi.commons.handleParams(params, { + username: 'string', + password: 'string', + email: 'string' + }); + if (!params.email) { return ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空'); } + if (!params.password) { return ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空'); } - var checkRepeat = await userInst.checkRepeat(params.email);//然后检查是否已经存在该用户 + let checkRepeat = await userInst.checkRepeat(params.email);//然后检查是否已经存在该用户 + if (checkRepeat > 0) { return ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册'); } @@ -285,14 +298,16 @@ class userController extends baseController { role: 'member', add_time: yapi.commons.time(), up_time: yapi.commons.time() - } + }; + if (!data.username) { data.username = data.email.substr(0, data.email.indexOf('@')); } + try { let user = await userInst.save(data); - this.setLoginCookie(user._id, user.passsalt) + this.setLoginCookie(user._id, user.passsalt); ctx.body = yapi.commons.resReturn({ uid: user._id, email: user.email, @@ -302,15 +317,14 @@ class userController extends baseController { role: 'member' }); yapi.commons.sendMail({ - to: params.email, - contents: `欢迎注册,您的账号 ${params.email} 已经注册成功` - }) + to: user.email, + contents: `

    亲爱的用户:

    您好,感谢使用YApi,您的账号 ${params.email} 已经注册成功

    ` + }); } catch (e) { ctx.body = yapi.commons.resReturn(null, 401, e.message); } } - /** * 获取用户列表 * @interface /user/list @@ -322,11 +336,10 @@ class userController extends baseController { * @returns {Object} * @example */ - - async list(ctx){ + async list(ctx) { let page = ctx.request.query.page || 1, limit = ctx.request.query.limit || 10; - + const userInst = yapi.getInst(userModel); try { let user = await userInst.listWithPaging(page, limit); @@ -335,8 +348,8 @@ class userController extends baseController { total: Math.ceil(count / limit), list: user }); - } catch(e) { - return ctx.body = yapi.commons.resReturn(null,402,e.message); + } catch (e) { + return ctx.body = yapi.commons.resReturn(null, 402, e.message); } } @@ -350,19 +363,22 @@ class userController extends baseController { * @returns {Object} * @example */ - async findById(ctx) { //根据id获取用户信息 try { - var userInst = yapi.getInst(userModel); + let userInst = yapi.getInst(userModel); let id = ctx.request.query.id; + if (!id) { return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空'); } + let result = await userInst.findById(id); - if(!result){ - return ctx.body = yapi.commons.resReturn(null,402,"不存在的用户"); + + if (!result) { + return ctx.body = yapi.commons.resReturn(null, 402, '不存在的用户'); } - return ctx.body = yapi.commons.resReturn({ + + return ctx.body = yapi.commons.resReturn({ uid: result._id, username: result.username, email: result.email, @@ -370,8 +386,8 @@ class userController extends baseController { add_time: result.add_time, up_time: result.up_time }); - }catch(e){ - return ctx.body = yapi.commons.resReturn(null,402,e.message); + } catch (e) { + return ctx.body = yapi.commons.resReturn(null, 402, e.message); } } @@ -386,16 +402,20 @@ class userController extends baseController { * @example */ async del(ctx) { //根据id删除一个用户 - try { + try { if (this.getRole() !== 'admin') { return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.'); } - var userInst = yapi.getInst(userModel); + + let userInst = yapi.getInst(userModel); let id = ctx.request.body.id; + if (!id) { return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空'); } + let result = await userInst.del(id); + ctx.body = yapi.commons.resReturn(result); } catch (e) { ctx.body = yapi.commons.resReturn(null, 402, e.message); @@ -415,26 +435,36 @@ class userController extends baseController { * @returns {Object} * @example */ - async update(ctx){ //更新用户信息 - try{ + async update(ctx) { //更新用户信息 + try { let params = ctx.request.body; - if(this.getRole() !== 'admin' && params.uid != this.getUid()){ - return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); + + params = yapi.commons.handleParams(params, { + username: 'string', + email: 'string' + }); + + if (this.getRole() !== 'admin' && params.uid != this.getUid()) { + return ctx.body = yapi.commons.resReturn(null, 401, '没有权限'); } - var userInst = yapi.getInst(userModel); + + let userInst = yapi.getInst(userModel); let id = params.uid; + if (!id) { return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空'); } - let data ={ + let data = { up_time: yapi.commons.time() }; - if(this.getRole() === 'admin'){ - params.role && (data.role = params.role) + + if (this.getRole() === 'admin') { + params.role && (data.role = params.role); } - params.username && (data.username = params.username) - params.email && (data.email = params.email) + + params.username && (data.username = params.username); + params.email && (data.email = params.email); if (data.email) { var checkRepeat = await userInst.checkRepeat(data.email);//然后检查是否已经存在该用户 @@ -443,8 +473,8 @@ class userController extends baseController { } } - let result = await userInst.update(id, data); + ctx.body = yapi.commons.resReturn(result); } catch (e) { ctx.body = yapi.commons.resReturn(null, 402, e.message); @@ -492,10 +522,58 @@ class userController extends baseController { ]; let filteredRes = common.filterRes(queryList, rules); - console.log(queryList) + console.log(queryList); // eslint-disable-line return ctx.body = yapi.commons.resReturn(filteredRes, 0, 'ok'); } + + /** + * 根据路由id获取面包屑数据 + * @interface /user/nav + * @method GET + * @category user + * @foldnumber 10 + * @param {String} type 可选group|interface|project + * @param {Number} id + * @return {Object} + * @example ./api/user/nav.json + */ + async nav(ctx) { + let { id, type } = ctx.request.query; + let result = {}; + try { + if (type === 'interface') { + let interfaceInst = yapi.getInst(interfaceModel); + let interfaceData = await interfaceInst.get(id) + result["interface_id"] = interfaceData._id; + result["interface_name"] = interfaceData.path; + type = 'project'; + id = interfaceData.project_id; + } + + if (type === 'project') { + let projectInst = yapi.getInst(projectModel); + let projectData = await projectInst.get(id); + result["project_id"] = projectData._id; + result["project_name"] = projectData.prd_host + projectData.basepath; + type = 'group'; + id = projectData.group_id + } + + if (type === 'group') { + let groupInst = yapi.getInst(groupModel); + let groupData = await groupInst.get(id); + result["group_id"] = groupData._id; + result["group_name"] = groupData.group_name; + } + + return ctx.body = yapi.commons.resReturn(result) + } + catch (e) { + return ctx.body = yapi.commons.resReturn(result, 422, e.message) + } + } + } module.exports = userController; diff --git a/exampleCode/api/user/nav.json b/exampleCode/api/user/nav.json new file mode 100644 index 00000000..9b6b6afb --- /dev/null +++ b/exampleCode/api/user/nav.json @@ -0,0 +1,12 @@ +{ + "errcode": 0, + "errmsg": "success", + "data": { + "interface_id": 2746, + "interface_name": "/a/c", + "project_id": 2481, + "project_name": "www.xxx.com/api", + "group_id": 181, + "group_name": "YMFE" + } +} \ No newline at end of file diff --git a/server/controllers/user.js b/server/controllers/user.js index ab163faa..a54f9e34 100644 --- a/server/controllers/user.js +++ b/server/controllers/user.js @@ -4,6 +4,10 @@ import baseController from './base.js'; import request from 'request'; import common from '../utils/commons.js'; +import interfaceModel from '../models/interface.js' +import groupModel from '../models/group.js' +import projectModel from '../models/project.js' + const jwt = require('jsonwebtoken'); class userController extends baseController { @@ -72,6 +76,7 @@ class userController extends baseController { ctx.body = yapi.commons.resReturn('ok'); } + /** * 第三方登录需要提供一个request方法和 token字段,暂时只支持qunar第三方 * @return {email: String, username: String} @@ -442,7 +447,7 @@ class userController extends baseController { } let result = await userInst.update(id, data); - + ctx.body = yapi.commons.resReturn(result); } catch (e) { ctx.body = yapi.commons.resReturn(null, 402, e.message); @@ -494,6 +499,54 @@ class userController extends baseController { return ctx.body = yapi.commons.resReturn(filteredRes, 0, 'ok'); } + + /** + * 根据路由id获取面包屑数据 + * @interface /user/nav + * @method GET + * @category user + * @foldnumber 10 + * @param {String} type 可选group|interface|project + * @param {Number} id + * @return {Object} + * @example ./api/user/nav.json + */ + async nav(ctx) { + let { id, type } = ctx.request.query; + let result = {}; + try { + if (type === 'interface') { + let interfaceInst = yapi.getInst(interfaceModel); + let interfaceData = await interfaceInst.get(id) + result["interface_id"] = interfaceData._id; + result["interface_name"] = interfaceData.path; + type = 'project'; + id = interfaceData.project_id; + } + + if (type === 'project') { + let projectInst = yapi.getInst(projectModel); + let projectData = await projectInst.get(id); + result["project_id"] = projectData._id; + result["project_name"] = projectData.prd_host + projectData.basepath; + type = 'group'; + id = projectData.group_id + } + + if (type === 'group') { + let groupInst = yapi.getInst(groupModel); + let groupData = await groupInst.get(id); + result["group_id"] = groupData._id; + result["group_name"] = groupData.group_name; + } + + return ctx.body = yapi.commons.resReturn(result) + } + catch (e) { + return ctx.body = yapi.commons.resReturn(result, 422, e.message) + } + } + } module.exports = userController; \ No newline at end of file diff --git a/server/models/group.js b/server/models/group.js index 8c2b8dec..3ef76c4f 100644 --- a/server/models/group.js +++ b/server/models/group.js @@ -21,6 +21,12 @@ class groupModel extends baseModel { return m.save(); } + get(id) { + return this.model.findOne({ + _id: id + }).exec(); + } + checkRepeat(name) { return this.model.count({ group_name: name diff --git a/server/router.js b/server/router.js index e5bc2a8e..c6354085 100644 --- a/server/router.js +++ b/server/router.js @@ -50,6 +50,7 @@ createAction('user', 'logout', 'get', 'logout'); createAction('user', 'login_by_token', 'post', 'loginByToken'); createAction('user', 'change_password', 'post', 'changePassword'); createAction('user', 'search', 'get', 'search'); +createAction('user', 'nav', 'get', 'nav') //project diff --git a/server_dist/controllers/user.js b/server_dist/controllers/user.js index 50cd044b..4d84e88d 100644 --- a/server_dist/controllers/user.js +++ b/server_dist/controllers/user.js @@ -52,6 +52,18 @@ var _commons = require('../utils/commons.js'); var _commons2 = _interopRequireDefault(_commons); +var _interface = require('../models/interface.js'); + +var _interface2 = _interopRequireDefault(_interface); + +var _group = require('../models/group.js'); + +var _group2 = _interopRequireDefault(_group); + +var _project = require('../models/project.js'); + +var _project2 = _interopRequireDefault(_project); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var jwt = require('jsonwebtoken'); @@ -1037,6 +1049,106 @@ var userController = function (_baseController) { return search; }() + + /** + * 根据路由id获取面包屑数据 + * @interface /user/nav + * @method GET + * @category user + * @foldnumber 10 + * @param {String} type 可选group|interface|project + * @param {Number} id + * @return {Object} + * @example ./api/user/nav.json + */ + + }, { + key: 'nav', + value: function () { + var _ref14 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee14(ctx) { + var _ctx$request$query, id, type, result, interfaceInst, interfaceData, projectInst, projectData, groupInst, groupData; + + return _regenerator2.default.wrap(function _callee14$(_context14) { + while (1) { + switch (_context14.prev = _context14.next) { + case 0: + _ctx$request$query = ctx.request.query, id = _ctx$request$query.id, type = _ctx$request$query.type; + result = {}; + _context14.prev = 2; + + if (!(type === 'interface')) { + _context14.next = 12; + break; + } + + interfaceInst = _yapi2.default.getInst(_interface2.default); + _context14.next = 7; + return interfaceInst.get(id); + + case 7: + interfaceData = _context14.sent; + + result["interface_id"] = interfaceData._id; + result["interface_name"] = interfaceData.path; + type = 'project'; + id = interfaceData.project_id; + + case 12: + if (!(type === 'project')) { + _context14.next = 21; + break; + } + + projectInst = _yapi2.default.getInst(_project2.default); + _context14.next = 16; + return projectInst.get(id); + + case 16: + projectData = _context14.sent; + + result["project_id"] = projectData._id; + result["project_name"] = projectData.prd_host + projectData.basepath; + type = 'group'; + id = projectData.group_id; + + case 21: + if (!(type === 'group')) { + _context14.next = 28; + break; + } + + groupInst = _yapi2.default.getInst(_group2.default); + _context14.next = 25; + return groupInst.get(id); + + case 25: + groupData = _context14.sent; + + result["group_id"] = groupData._id; + result["group_name"] = groupData.group_name; + + case 28: + return _context14.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result)); + + case 31: + _context14.prev = 31; + _context14.t0 = _context14['catch'](2); + return _context14.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result, 422, _context14.t0.message)); + + case 34: + case 'end': + return _context14.stop(); + } + } + }, _callee14, this, [[2, 31]]); + })); + + function nav(_x13) { + return _ref14.apply(this, arguments); + } + + return nav; + }() }]); return userController; }(_base2.default); diff --git a/server_dist/models/group.js b/server_dist/models/group.js index 5b0030f4..475296c0 100644 --- a/server_dist/models/group.js +++ b/server_dist/models/group.js @@ -60,6 +60,13 @@ var groupModel = function (_baseModel) { var m = new this.model(data); return m.save(); } + }, { + key: 'get', + value: function get(id) { + return this.model.findOne({ + _id: id + }).exec(); + } }, { key: 'checkRepeat', value: function checkRepeat(name) { diff --git a/server_dist/router.js b/server_dist/router.js index d0af5bec..87ea8b3c 100644 --- a/server_dist/router.js +++ b/server_dist/router.js @@ -81,6 +81,7 @@ createAction('user', 'logout', 'get', 'logout'); createAction('user', 'login_by_token', 'post', 'loginByToken'); createAction('user', 'change_password', 'post', 'changePassword'); createAction('user', 'search', 'get', 'search'); +createAction('user', 'nav', 'get', 'nav'); //project createAction('project', 'add', 'post', 'add');