This commit is contained in:
喻希里 2017-08-30 10:44:14 +08:00
commit 704e3c1d8d
7 changed files with 101 additions and 65 deletions

View File

@ -85,10 +85,8 @@ class InterfaceEditForm extends Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
if (values.res_body_type === 'json') values.res_body = this.state.res_body;
values.req_params = this.state.req_params;
// values.req_body_other = this.state.req_body_other;
if (!err) {
if (values.res_body_type === 'json') values.res_body = this.state.res_body;
values.method = this.state.method;
let isfile = false, isHavaContentType = false;
if (values.req_body_type === 'form') {
@ -130,7 +128,7 @@ class InterfaceEditForm extends Component {
values.req_query = values.req_query ? values.req_query.filter(item => item.name !== '') : []
if (HTTP_METHOD[values.method].request_body !== true) {
values.req_params = []
values.req_body_form = []
}
this.props.onSubmit(values)
}

View File

@ -95,8 +95,6 @@ class ProjectMessage extends Component {
this.props.getProjectMsg(this.props.projectId);
message.success('修改成功! ');
// this.props.history.push('/group');
} else {
message.error(res.payload.data.errmsg);
}
}).catch(() => {
});

View File

@ -2,6 +2,7 @@ import interfaceModel from '../models/interface.js';
import interfaceCatModel from '../models/interfaceCat.js';
import interfaceCaseModel from '../models/interfaceCase.js'
import _ from 'underscore';
import baseController from './base.js';
import yapi from '../yapi.js';
import userModel from '../models/user.js';
@ -61,6 +62,7 @@ class interfaceController extends baseController {
}
params.method = params.method || 'GET';
params.method = params.method.toUpperCase();
params.req_params = params.req_params || [];
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
if (!params.project_id) {
@ -105,7 +107,23 @@ class interfaceController extends baseController {
if (params.req_body_form) {
data.req_body_form = params.req_body_form;
}
if (params.req_params && Array.isArray(params.req_params) && params.req_params.length > 0) {
if (params.path.indexOf(":") > 0) {
let paths = params.path.split("/"), name, i;
for (i = 1; i < paths.length; i++) {
if (paths[i][0] === ':') {
name = paths[i].substr(1);
if (!_.find(params.req_params, { name: name })) {
params.req_params.push({
name: name,
desc: ''
})
}
}
}
}
if ( params.req_params.length > 0) {
data.type = 'var'
data.req_params = params.req_params;
} else {
@ -116,9 +134,9 @@ class interfaceController extends baseController {
}
let result = await this.Model.save(data);
// let project = await this.projectModel.get(params.project_id);
this.catModel.get(params.catid).then((cate)=>{
this.catModel.get(params.catid).then((cate) => {
let username = this.getUsername();
yapi.commons.saveLog({
content: `用户 "${username}" 为分类 "${cate.name}" 添加了接口 "${data.title}"`,
@ -128,7 +146,7 @@ class interfaceController extends baseController {
typeid: params.project_id
});
});
ctx.body = yapi.commons.resReturn(result);
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
@ -278,7 +296,7 @@ class interfaceController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
}
if (params.path && (params.path !== interfaceData.path || params.method !== interfaceData.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 + ']');
@ -346,7 +364,7 @@ class interfaceController extends baseController {
let result = await this.Model.up(id, data);
let username = this.getUsername();
if (params.catid) {
this.catModel.get(+params.catid).then((cate)=>{
this.catModel.get(+params.catid).then((cate) => {
yapi.commons.saveLog({
content: `用户 "${username}" 更新了分类 "${cate.name}" 下的接口 "${data.title}"`,
type: 'project',
@ -357,7 +375,7 @@ class interfaceController extends baseController {
});
} else {
let cateid = interfaceData.catid;
this.catModel.get(cateid).then((cate)=>{
this.catModel.get(cateid).then((cate) => {
yapi.commons.saveLog({
content: `用户 "${username}" 更新了分类 "${cate.name}" 下的接口 "${data.title}"`,
type: 'project',
@ -368,7 +386,7 @@ class interfaceController extends baseController {
});
}
ctx.body = yapi.commons.resReturn(result);
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
@ -408,7 +426,7 @@ class interfaceController extends baseController {
let result = await this.Model.del(id);
await this.caseModel.delByInterfaceId(id);
let username = this.getUsername();
this.catModel.get(inter.catid).then((cate)=>{
this.catModel.get(inter.catid).then((cate) => {
yapi.commons.saveLog({
content: `用户 "${username}" 删除了分类 "${cate.name}" 下的接口 "${inter.title}"`,
type: 'project',
@ -417,7 +435,7 @@ class interfaceController extends baseController {
typeid: cate.project_id
});
})
ctx.body = yapi.commons.resReturn(result);
} catch (err) {
@ -507,7 +525,7 @@ class interfaceController extends baseController {
name: params.name,
desc: params.desc,
up_time: yapi.commons.time()
});
});
let username = this.getUsername();
let cate = await this.catModel.get(params.catid);

View File

@ -344,7 +344,7 @@ class projectController extends baseController {
for(let index=0, item, r = 1; index< result.length; index++){
item = result[index].toObject();
if(item.project_type === 'private' && auth === false){
r = await this.Model.checkMemberRepeat(this.getUid());
r = await this.Model.checkMemberRepeat(item._id, this.getUid());
if(r === 0){
continue;
}

View File

@ -44,6 +44,10 @@ var _interfaceCase = require('../models/interfaceCase.js');
var _interfaceCase2 = _interopRequireDefault(_interfaceCase);
var _underscore = require('underscore');
var _underscore2 = _interopRequireDefault(_underscore);
var _base = require('./base.js');
var _base2 = _interopRequireDefault(_base);
@ -113,7 +117,7 @@ var interfaceController = function (_baseController) {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var _this2 = this;
var params, auth, checkRepeat, data, result;
var params, auth, checkRepeat, data, paths, name, i, result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
@ -145,47 +149,48 @@ var interfaceController = function (_baseController) {
case 7:
params.method = params.method || 'GET';
params.method = params.method.toUpperCase();
params.req_params = params.req_params || [];
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
if (params.project_id) {
_context.next = 12;
_context.next = 13;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 12:
case 13:
if (params.path) {
_context.next = 14;
_context.next = 15;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口请求路径不能为空'));
case 14:
case 15:
if (_yapi2.default.commons.verifyPath(params.path)) {
_context.next = 16;
_context.next = 17;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/'));
case 16:
_context.next = 18;
case 17:
_context.next = 19;
return this.Model.checkRepeat(params.project_id, params.path, params.method);
case 18:
case 19:
checkRepeat = _context.sent;
if (!(checkRepeat > 0)) {
_context.next = 21;
_context.next = 22;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']'));
case 21:
_context.prev = 21;
case 22:
_context.prev = 22;
data = {
project_id: params.project_id,
catid: params.catid,
@ -210,7 +215,24 @@ var interfaceController = function (_baseController) {
if (params.req_body_form) {
data.req_body_form = params.req_body_form;
}
if (params.req_params && Array.isArray(params.req_params) && params.req_params.length > 0) {
if (params.path.indexOf(":") > 0) {
paths = params.path.split("/"), name = void 0, i = void 0;
for (i = 1; i < paths.length; i++) {
if (paths[i][0] === ':') {
name = paths[i].substr(1);
if (!_underscore2.default.find(params.req_params, { name: name })) {
params.req_params.push({
name: name,
desc: ''
});
}
}
}
}
if (params.req_params.length > 0) {
data.type = 'var';
data.req_params = params.req_params;
} else {
@ -220,10 +242,10 @@ var interfaceController = function (_baseController) {
data.req_body_other = params.req_body_other;
}
_context.next = 29;
_context.next = 31;
return this.Model.save(data);
case 29:
case 31:
result = _context.sent;
@ -240,21 +262,21 @@ var interfaceController = function (_baseController) {
});
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 37;
_context.next = 39;
break;
case 34:
_context.prev = 34;
_context.t0 = _context['catch'](21);
case 36:
_context.prev = 36;
_context.t0 = _context['catch'](22);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
case 37:
case 39:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[21, 34]]);
}, _callee, this, [[22, 36]]);
}));
function add(_x) {

View File

@ -84,7 +84,7 @@ var interfaceColController = function (_baseController) {
(0, _createClass3.default)(interfaceColController, [{
key: 'list',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(ctx) {
var id, result, i;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
@ -159,7 +159,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'addCol',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(ctx) {
var params, auth, result, username;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
@ -265,7 +265,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'getCaseList',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(ctx) {
var id, inst, result, index, interfaceData, projectData;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
@ -357,7 +357,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'addCase',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(ctx) {
var _this2 = this;
var params, auth, result, username;
@ -494,7 +494,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'upCase',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(ctx) {
var _this3 = this;
var params, caseData, auth, result, username;
@ -609,7 +609,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'getCase',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(ctx) {
var id, result, data, projectData;
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
@ -707,7 +707,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'upCol',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(ctx) {
var params, id, colData, auth, result, username;
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
@ -792,7 +792,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'upCaseIndex',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(ctx) {
var _this4 = this;
var params;
@ -861,7 +861,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'delCol',
value: function () {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(ctx) {
var id, colData, auth, result, username;
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
@ -947,7 +947,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'delCase',
value: function () {
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(ctx) {
var _this5 = this;
var caseid, caseData, auth, result, username;

View File

@ -148,7 +148,7 @@ var projectController = function (_baseController) {
}, {
key: 'add',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(ctx) {
var params, checkRepeat, data, result, colInst, catInst, username;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
@ -320,7 +320,7 @@ var projectController = function (_baseController) {
}, {
key: 'addMember',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(ctx) {
var params, check, userdata, result, username;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
@ -443,7 +443,7 @@ var projectController = function (_baseController) {
}, {
key: 'delMember',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(ctx) {
var _this2 = this;
var params, check, result, username;
@ -541,7 +541,7 @@ var projectController = function (_baseController) {
}, {
key: 'getUserdata',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(uid, role) {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(uid, role) {
var userInst, userData;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
@ -599,7 +599,7 @@ var projectController = function (_baseController) {
}, {
key: 'getMemberList',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(ctx) {
var params, project;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
@ -661,7 +661,7 @@ var projectController = function (_baseController) {
}, {
key: 'get',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(ctx) {
var params, result, catInst, cat;
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
@ -746,7 +746,7 @@ var projectController = function (_baseController) {
}, {
key: 'list',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(ctx) {
var _this3 = this;
var group_id, project_list, auth, result, follow, _loop, index, item, r, _ret;
@ -781,7 +781,7 @@ var projectController = function (_baseController) {
case 12:
follow = _context8.sent;
_loop = _regenerator2.default.mark(function _loop(index, _item, _r) {
_loop = /*#__PURE__*/_regenerator2.default.mark(function _loop(index, _item, _r) {
var f;
return _regenerator2.default.wrap(function _loop$(_context7) {
while (1) {
@ -795,7 +795,7 @@ var projectController = function (_baseController) {
}
_context7.next = 4;
return _this3.Model.checkMemberRepeat(_this3.getUid());
return _this3.Model.checkMemberRepeat(_item._id, _this3.getUid());
case 4:
_r = _context7.sent;
@ -898,7 +898,7 @@ var projectController = function (_baseController) {
}, {
key: 'del',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(ctx) {
var id, interfaceInst, interfaceColInst, interfaceCaseInst, result;
return _regenerator2.default.wrap(function _callee8$(_context9) {
while (1) {
@ -991,7 +991,7 @@ var projectController = function (_baseController) {
}, {
key: 'changeMemberRole',
value: function () {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(ctx) {
var _this4 = this;
var params, projectInst, check, result, username;
@ -1107,7 +1107,7 @@ var projectController = function (_baseController) {
}, {
key: 'upSet',
value: function () {
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(ctx) {
var _this5 = this;
var id, data, result;
@ -1197,7 +1197,7 @@ var projectController = function (_baseController) {
}, {
key: 'up',
value: function () {
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(ctx) {
var id, params, projectData, checkRepeat, data, result, username;
return _regenerator2.default.wrap(function _callee11$(_context12) {
while (1) {
@ -1346,7 +1346,7 @@ var projectController = function (_baseController) {
}, {
key: 'search',
value: function () {
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(ctx) {
var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(ctx) {
var q, projectList, groupList, projectRules, groupRules, queryList;
return _regenerator2.default.wrap(function _callee12$(_context13) {
while (1) {
@ -1421,7 +1421,7 @@ var projectController = function (_baseController) {
}, {
key: 'download',
value: function () {
var _ref13 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee13(ctx) {
var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(ctx) {
var project_id, interfaceInst, count, arr, fileName, res;
return _regenerator2.default.wrap(function _callee13$(_context14) {
while (1) {