diff --git a/.eslintrc.js b/.eslintrc.js index 1c80996a..916d58fd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -37,6 +37,7 @@ module.exports = { "error", "always" ], - "strict": 0 + "strict": 0, + "comma-dangle": ["error", "never"] } }; \ No newline at end of file diff --git a/client/components/Footer/Footer.js b/client/components/Footer/Footer.js index a50fe4e1..b5af007c 100644 --- a/client/components/Footer/Footer.js +++ b/client/components/Footer/Footer.js @@ -60,7 +60,7 @@ Footer.defaultProps = { linkList: [ { itemTitle: '源码仓库', - itemLink: 'http://gitlab.corp.qunar.com/mfe/yapi.git' + itemLink: 'https://github.com/YMFE/yapi' } ] diff --git a/client/components/Header/Header.js b/client/components/Header/Header.js index 6dafc198..222dac39 100644 --- a/client/components/Header/Header.js +++ b/client/components/Header/Header.js @@ -195,4 +195,4 @@ export default class HeaderCom extends Component { ) } -} \ No newline at end of file +} diff --git a/client/components/Header/Search/Search.scss b/client/components/Header/Search/Search.scss index 5de982eb..610ccf7f 100644 --- a/client/components/Header/Search/Search.scss +++ b/client/components/Header/Search/Search.scss @@ -2,14 +2,9 @@ $color-grey:#979DA7; .search-wrapper{ .search-input{ - border:1px solid $color-grey; - color: $color-grey; width: 2rem; - transition: width 2s; - //background-color:rgba(0,0,0,0.5); + //transition: width 2s; } .srch-icon{ - color: $color-grey; - font-weight: bold; } } diff --git a/client/containers/AddInterface/AddInterface.scss b/client/containers/AddInterface/AddInterface.scss index fb33b696..3998491c 100644 --- a/client/containers/AddInterface/AddInterface.scss +++ b/client/containers/AddInterface/AddInterface.scss @@ -2,6 +2,7 @@ .add-interface-box { -webkit-box-flex: 1; + min-height: 5rem; font-size: .14rem; overflow-x: hidden; overflow-y: auto; diff --git a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js index cd2230f7..ba835fc6 100644 --- a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js +++ b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' -import { Button, Input, Select, Card, Alert } from 'antd' +import { Button, Input, Select, Card, Alert, Spin } from 'antd' import { autobind } from 'core-decorators'; import crossRequest from 'cross-request'; import { withRouter } from 'react-router'; @@ -111,7 +111,8 @@ export default class InterfaceTest extends Component { params, paramsNotJson, headers, - currDomain: domains.prd + currDomain: domains.prd, + loading: false }); } @@ -128,6 +129,8 @@ export default class InterfaceTest extends Component { query }); + this.setState({ loading: true }) + crossRequest({ url: href, method, @@ -135,7 +138,18 @@ export default class InterfaceTest extends Component { data: params, success: (res, header) => { console.log(header) + try { + res = JSON.parse(res); + } catch (e) { + null; + } this.setState({res}) + this.setState({ loading: false }) + }, + error: (err, header) => { + console.log(header) + this.setState({res: err || '请求失败'}) + this.setState({ loading: false }) } }) } @@ -205,6 +219,11 @@ export default class InterfaceTest extends Component {
{interfaceName}
+ + + + + - +
@@ -267,15 +291,17 @@ export default class InterfaceTest extends Component {
-
-
- + +
+
+ +
-
+
) diff --git a/client/containers/Interface/Interface.js b/client/containers/Interface/Interface.js index 6903506c..a7083f62 100644 --- a/client/containers/Interface/Interface.js +++ b/client/containers/Interface/Interface.js @@ -78,7 +78,7 @@ class Interface extends Component { render () { const { interfaceData, projectMember, modalVisible } = this.props return ( -
+
diff --git a/client/containers/Interface/Interface.scss b/client/containers/Interface/Interface.scss index 4f47a523..f2f6262f 100644 --- a/client/containers/Interface/Interface.scss +++ b/client/containers/Interface/Interface.scss @@ -1,5 +1,9 @@ @import '../../styles/mixin.scss'; +.g-doc { + min-height: 5rem; +} + /* .interface-box.css */ .interface-box { @include row-width-limit; diff --git a/client/containers/ProjectGroups/GroupList/GroupList.js b/client/containers/ProjectGroups/GroupList/GroupList.js index 828091e0..a13c8675 100644 --- a/client/containers/ProjectGroups/GroupList/GroupList.js +++ b/client/containers/ProjectGroups/GroupList/GroupList.js @@ -1,13 +1,12 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' -import { Button, Icon, Modal, Input, message, Menu, Row, Col } from 'antd' +import { Button, Icon, Popconfirm, Modal, Input, message, Menu, Row, Col } from 'antd' import { autobind } from 'core-decorators'; import axios from 'axios'; import { withRouter } from 'react-router'; const { TextArea } = Input; const Search = Input.Search; -const confirm = Modal.confirm; const TYPE_EDIT = 'edit'; import { @@ -164,21 +163,15 @@ export default class GroupList extends Component { deleteGroup() { const self = this; const { currGroup } = self.props; - confirm({ - title: `你确定要删除分组 ${currGroup.group_name}?`, - content: `分组简介:${currGroup.group_desc}`, - onOk() { - axios.post('/group/del', {id: currGroup._id}).then(res => { - if (res.data.errcode) { - message.error(res.data.errmsg); - } else { - message.success('删除成功'); - self.props.fetchGroupList().then(() => { - const currGroup = self.props.groupList[0] || { group_name: '', group_desc: '' }; - self.setState({groupList: self.props.groupList}); - self.props.setCurrGroup(currGroup) - }); - } + axios.post('/group/del', {id: currGroup._id}).then(res => { + if (res.data.errcode) { + message.error(res.data.errmsg); + } else { + message.success('删除成功'); + self.props.fetchGroupList().then(() => { + const currGroup = self.props.groupList[0] || { group_name: '', group_desc: '' }; + self.setState({groupList: self.props.groupList}); + self.props.setCurrGroup(currGroup) }); } }); @@ -205,7 +198,9 @@ export default class GroupList extends Component {
{currGroup.group_name}
this.showModal(TYPE_EDIT)}/> - + + +
简介:{currGroup.group_desc}
diff --git a/client/containers/ProjectGroups/ProjectGroups.scss b/client/containers/ProjectGroups/ProjectGroups.scss index e57e92c8..3a9b6198 100644 --- a/client/containers/ProjectGroups/ProjectGroups.scss +++ b/client/containers/ProjectGroups/ProjectGroups.scss @@ -2,5 +2,6 @@ .g-doc { @include row-width-limit; + min-height: 5rem; margin: .24rem auto; } diff --git a/client/containers/ProjectGroups/ProjectList/ProjectList.js b/client/containers/ProjectGroups/ProjectList/ProjectList.js index f31d22ea..811b5e79 100644 --- a/client/containers/ProjectGroups/ProjectList/ProjectList.js +++ b/client/containers/ProjectGroups/ProjectList/ProjectList.js @@ -71,7 +71,7 @@ const getColumns = (data, props) => { changeUpdateModal(true, index)}>修改 - + 删除 diff --git a/client/containers/ProjectGroups/ProjectList/ProjectList.scss b/client/containers/ProjectGroups/ProjectList/ProjectList.scss index 5950d67b..1fefd8a1 100644 --- a/client/containers/ProjectGroups/ProjectList/ProjectList.scss +++ b/client/containers/ProjectGroups/ProjectList/ProjectList.scss @@ -1,9 +1,8 @@ .m-container{ background-color: #fff; - padding: 16px 24px; + padding: 24px; box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20); border-radius: 4px; - text-align: right; } .m-table { diff --git a/client/containers/User/LeftMenu.js b/client/containers/User/LeftMenu.js index 5a3acec9..7b919d6d 100644 --- a/client/containers/User/LeftMenu.js +++ b/client/containers/User/LeftMenu.js @@ -83,7 +83,7 @@ class LeftMenu extends Component { const { dataSource } = this.state; return (
-
用户名 : {`${this.props.curUserName}`}
+
用户名 :{`${this.props.curUserName}`}
diff --git a/client/containers/User/List.js b/client/containers/User/List.js index 2ae46fe5..15567696 100755 --- a/client/containers/User/List.js +++ b/client/containers/User/List.js @@ -108,7 +108,7 @@ class List extends Component { 查看 - {this.confirm(item._id)}} okText="Yes" cancelText="No"> + {this.confirm(item._id)}} okText="确定" cancelText="取消"> 删除 diff --git a/client/containers/User/Profile.js b/client/containers/User/Profile.js index 3a256867..ef276f50 100644 --- a/client/containers/User/Profile.js +++ b/client/containers/User/Profile.js @@ -132,14 +132,14 @@ class Profile extends Component { userNameEditHtml =
{userinfo.username}   {/* { this.handleEdit('usernameEdit', true) }}>修改*/} - +
} else { userNameEditHtml =
- - + +
} @@ -148,14 +148,14 @@ class Profile extends Component { emailEditHtml =
{userinfo.email}   {/* { this.handleEdit('emailEdit', true) }} >修改*/} - +
} else { emailEditHtml =
- - + +
} @@ -164,7 +164,7 @@ class Profile extends Component { roleEditHtml =
{roles[userinfo.role]}   {/* { this.handleEdit('roleEdit', true) }} >修改*/} - +
} else { roleEditHtml = - - + +
} diff --git a/client/containers/User/User.js b/client/containers/User/User.js index 9be25f22..fd5927b7 100755 --- a/client/containers/User/User.js +++ b/client/containers/User/User.js @@ -6,6 +6,7 @@ import LeftMenu from './LeftMenu.js' import List from './List.js' import PropTypes from 'prop-types' import Profile from './Profile.js' +import { Row, Col } from 'antd'; @connect() class User extends Component { @@ -22,19 +23,22 @@ class User extends Component { } render () { - - + + return ( -
-
- - - - -
+
+ + + + + + + + +
- ) + ) } } -export default User \ No newline at end of file +export default User diff --git a/client/containers/User/index.scss b/client/containers/User/index.scss index 75cbbb3b..d33d83ef 100644 --- a/client/containers/User/index.scss +++ b/client/containers/User/index.scss @@ -1,5 +1,10 @@ @import '../../styles/mixin.scss'; +.g-doc { + margin: .24rem auto; + min-height: 5rem; +} + /* .user-box.css */ .user-box { @include row-width-limit; @@ -15,7 +20,6 @@ .user-list { - width: 216px; box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20); background: #FFF; border-radius:5px; @@ -30,15 +34,15 @@ } } .user-name{ - padding: 24px 0px; - text-align: center; + padding: 24px 10px; + // text-align: center; background-color: #34495e; color: white; font-size: 16px; border-top-left-radius:5px; - border-top-right-radius: 5px; + border-top-right-radius: 5px; span{ - margin-right: 10px; + margin-right: 5px; } } .router-content{ @@ -70,9 +74,6 @@ box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20); background: #FFF; border-radius:5px; - .ant-btn-group{ - margin-top: 12px; - } .user-item { min-height:35px; line-height:35px; @@ -87,8 +88,14 @@ #old_password{ margin-top: 0px; } + .ant-col-12{ + .ant-input{ + width: 70%; + margin-right: 24px; + } + } .ant-col-4{ - color: black; + color: rgba(0,0,0,0.85); padding: 0px 10px; text-indent: .7em; // background-color: #f1f3f6; diff --git a/config.json b/config.json new file mode 100644 index 00000000..be5bd2aa --- /dev/null +++ b/config.json @@ -0,0 +1,20 @@ +{ +"port": "3000", +"webhost": "yapi.local.qunar.com", +"adminAccount": "admin@admin.com", +"db": { +"servername": "10.86.40.194", +"DATABASE": "yapi", +"port": 27017, +"user": "test1", +"pass": "test1" +}, +"mail": { +"host": "smtp.163.com", +"port": 465, +"auth": { +"user": "hellosean1025@163.com", +"pass": "helloqunar123" +} +} +} \ No newline at end of file diff --git a/server/controllers/interface.js b/server/controllers/interface.js index a01f3bb1..642b0cb1 100644 --- a/server/controllers/interface.js +++ b/server/controllers/interface.js @@ -1,10 +1,10 @@ -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); } @@ -35,37 +35,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, '接口请求路径不能为空'); } - if(!yapi.commons.verifyPath(params.path)){ - return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/') + if (!yapi.commons.verifyPath(params.path)) { + return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/'); } - + 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 + ']'); - } + if (checkRepeat > 0) { + return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']'); + } - try{ + try { let data = { project_id: params.project_id, title: params.title, @@ -74,20 +76,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); } } @@ -101,16 +107,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); } } @@ -124,17 +132,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); } } @@ -165,55 +174,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 && !yapi.commons.verifyPath(params.path)){ - return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/') + 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 + ']'); + + 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); } } @@ -229,27 +259,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(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, err.message) + ctx.body = yapi.commons.resReturn(result); + } catch (err) { + ctx.body = yapi.commons.resReturn(null, 402, err.message); } } } diff --git a/server/models/interface.js b/server/models/interface.js index 0f760aa0..f5c4e1c9 100644 --- a/server/models/interface.js +++ b/server/models/interface.js @@ -82,10 +82,11 @@ class interfaceModel extends baseModel { _id: id }); } + up(id, data) { data.up_time = yapi.commons.time(); return this.model.update({ - _id: id, + _id: id }, data, { runValidators: true }); } } diff --git a/server/utils/commons.js b/server/utils/commons.js index c1a719b1..360d380a 100644 --- a/server/utils/commons.js +++ b/server/utils/commons.js @@ -23,10 +23,18 @@ exports.log = (msg, type) => { let f; switch (type) { - case 'log': f = console.log; break; - case 'warn': f = console.warn; break; - case 'error': f = console.error; break; - default: f = console.log; break; + case 'log': + f = console.log; + break; + case 'warn': + f = console.warn; + break; + case 'error': + f = console.error; + break; + default: + f = console.log; + break; } f(type + ':', msg); @@ -204,8 +212,10 @@ exports.handleParams = (params, keys) => { var filter = keys[key]; if (params[key]) { switch (filter) { - case 'string': params[key] = trim(params[key] + ''); break; - case 'number': params[key] = parseInt(params[key], 10); break; + case 'string': params[key] = trim(params[key] + ''); + break; + case 'number': params[key] = parseInt(params[key], 10); + break; default: params[key] = trim(params + ''); } } diff --git a/server/utils/db.js b/server/utils/db.js index 1a705e77..a427a0cf 100644 --- a/server/utils/db.js +++ b/server/utils/db.js @@ -2,8 +2,8 @@ import mongoose from 'mongoose'; import yapi from '../yapi.js'; import autoIncrement from 'mongoose-auto-increment'; -function model(model, schema){ - if(schema instanceof mongoose.Schema === false){ +function model(model, schema) { + if (schema instanceof mongoose.Schema === false) { schema = new mongoose.Schema(schema); } @@ -12,20 +12,20 @@ function model(model, schema){ return yapi.connect.model(model, schema, model); } -function connect(){ +function connect() { mongoose.Promise = global.Promise; let config = yapi.WEBCONFIG; let options = {}; - if(config.user){ - options.user = config.db.user, + if (config.user) { + options.user = config.db.user; options.pass = config.db.pass; } - + let db = mongoose.connect(`mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`, options); - db.then(function (res) { + db.then(function () { yapi.commons.log('mongodb load success...'); }, function (err) { yapi.commons.log(err, 'Mongo connect error'); @@ -37,7 +37,7 @@ function connect(){ yapi.db = model; -module.exports = { +module.exports = { model: model, connect: connect }; \ No newline at end of file diff --git a/server_dist/controllers/interface.js b/server_dist/controllers/interface.js index 039bd5ad..1a6941c4 100644 --- a/server_dist/controllers/interface.js +++ b/server_dist/controllers/interface.js @@ -94,6 +94,7 @@ var interfaceController = function (_baseController) { case 0: params = ctx.request.body; + params = _yapi2.default.commons.handleParams(params, { project_id: 'number', title: 'string', @@ -160,8 +161,12 @@ var interfaceController = function (_baseController) { }; - 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; + } _context.next = 22; return this.Model.save(data); @@ -301,7 +306,7 @@ var interfaceController = function (_baseController) { _context3.prev = 10; _context3.t0 = _context3['catch'](3); - ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message); + ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message); case 13: case 'end': @@ -356,6 +361,7 @@ var interfaceController = function (_baseController) { case 0: params = ctx.request.body; + params = _yapi2.default.commons.handleParams(params, { title: 'string', path: 'string', @@ -364,6 +370,7 @@ var interfaceController = function (_baseController) { }); params.method = params.method || 'GET'; params.method = params.method.toUpperCase(); + id = ctx.request.body.id; if (id) { @@ -412,18 +419,36 @@ var interfaceController = function (_baseController) { }; - 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; + } _context4.prev = 28; _context4.next = 31; diff --git a/server_dist/utils/commons.js b/server_dist/utils/commons.js index c43f49ee..792f05ab 100644 --- a/server_dist/utils/commons.js +++ b/server_dist/utils/commons.js @@ -47,13 +47,17 @@ exports.log = function (msg, type) { switch (type) { case 'log': - f = console.log;break; + f = console.log; + break; case 'warn': - f = console.warn;break; + f = console.warn; + break; case 'error': - f = console.error;break; + f = console.error; + break; default: - f = console.log;break; + f = console.log; + break; } f(type + ':', msg); @@ -231,9 +235,11 @@ exports.handleParams = function (params, keys) { if (params[key]) { switch (filter) { case 'string': - params[key] = trim(params[key] + '');break; + params[key] = trim(params[key] + ''); + break; case 'number': - params[key] = parseInt(params[key], 10);break; + params[key] = parseInt(params[key], 10); + break; default: params[key] = trim(params + ''); } diff --git a/server_dist/utils/db.js b/server_dist/utils/db.js index cb66a49a..21aae9bd 100644 --- a/server_dist/utils/db.js +++ b/server_dist/utils/db.js @@ -31,12 +31,13 @@ function connect() { var options = {}; if (config.user) { - options.user = config.db.user, options.pass = config.db.pass; + options.user = config.db.user; + options.pass = config.db.pass; } var db = _mongoose2.default.connect('mongodb://' + config.db.servername + ':' + config.db.port + '/' + config.db.DATABASE, options); - db.then(function (res) { + db.then(function () { _yapi2.default.commons.log('mongodb load success...'); }, function (err) { _yapi2.default.commons.log(err, 'Mongo connect error');