2017-07-05 16:17:58 +08:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var _regenerator = require('babel-runtime/regenerator');
|
|
|
|
|
|
|
|
|
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
|
|
|
|
|
|
|
|
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
|
|
|
|
|
|
|
|
|
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
|
|
|
|
|
|
|
|
|
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
|
|
|
|
|
|
|
|
|
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
|
|
|
|
|
|
|
|
|
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
|
|
|
|
|
|
|
|
|
var _createClass2 = require('babel-runtime/helpers/createClass');
|
|
|
|
|
|
|
|
|
|
var _createClass3 = _interopRequireDefault(_createClass2);
|
|
|
|
|
|
|
|
|
|
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
|
|
|
|
|
|
|
|
|
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
|
|
|
|
|
|
|
|
|
var _inherits2 = require('babel-runtime/helpers/inherits');
|
|
|
|
|
|
|
|
|
|
var _inherits3 = _interopRequireDefault(_inherits2);
|
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
|
var _project = require('../models/project.js');
|
|
|
|
|
|
|
|
|
|
var _project2 = _interopRequireDefault(_project);
|
|
|
|
|
|
|
|
|
|
var _yapi = require('../yapi.js');
|
|
|
|
|
|
|
|
|
|
var _yapi2 = _interopRequireDefault(_yapi);
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var _base = require('./base.js');
|
|
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
var _interface = require('../models/interface.js');
|
|
|
|
|
|
|
|
|
|
var _interface2 = _interopRequireDefault(_interface);
|
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var projectController = function (_baseController) {
|
|
|
|
|
(0, _inherits3.default)(projectController, _baseController);
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
function projectController(ctx) {
|
|
|
|
|
(0, _classCallCheck3.default)(this, projectController);
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var _this = (0, _possibleConstructorReturn3.default)(this, (projectController.__proto__ || (0, _getPrototypeOf2.default)(projectController)).call(this, ctx));
|
|
|
|
|
|
|
|
|
|
_this.Model = _yapi2.default.getInst(_project2.default);
|
|
|
|
|
return _this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加项目分组
|
|
|
|
|
* @interface /project/add
|
|
|
|
|
* @method POST
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {String} name 项目名称,不能为空
|
|
|
|
|
* @param {String} basepath 项目基本路径,不能为空
|
|
|
|
|
* @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
|
|
|
|
|
* @param {Number} group_id 项目分组id,不能为空
|
|
|
|
|
* @param {String} [desc] 项目描述
|
|
|
|
|
* @returns {Object}
|
|
|
|
|
* @example ./api/project/add.json
|
|
|
|
|
*/
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
(0, _createClass3.default)(projectController, [{
|
2017-07-06 19:21:54 +08:00
|
|
|
|
key: 'add',
|
|
|
|
|
value: function () {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var params, checkRepeat, checkRepeatDomain, data, result;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee$(_context) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
switch (_context.prev = _context.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
|
|
|
|
params = ctx.request.body;
|
|
|
|
|
|
|
|
|
|
if (params.group_id) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 3;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
if (params.name) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 5;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目名不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 5:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 7;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.checkNameRepeat(params.name);
|
|
|
|
|
|
|
|
|
|
case 7:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
checkRepeat = _context.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
if (!(checkRepeat > 0)) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 10;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
|
if (params.basepath) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 12;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目basepath不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
|
if (params.prd_host) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 14;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 14:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 16;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
|
|
|
|
|
|
|
|
|
case 16:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
checkRepeatDomain = _context.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
if (!(checkRepeatDomain > 0)) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 19;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 19:
|
|
|
|
|
data = {
|
|
|
|
|
name: params.name,
|
|
|
|
|
desc: params.desc,
|
|
|
|
|
prd_host: params.prd_host,
|
|
|
|
|
basepath: params.basepath,
|
|
|
|
|
members: [this.getUid()],
|
|
|
|
|
uid: this.getUid(),
|
|
|
|
|
group_id: params.group_id,
|
|
|
|
|
add_time: _yapi2.default.commons.time(),
|
|
|
|
|
up_time: _yapi2.default.commons.time()
|
|
|
|
|
};
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.prev = 20;
|
|
|
|
|
_context.next = 23;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.save(data);
|
|
|
|
|
|
|
|
|
|
case 23:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.next = 30;
|
2017-07-05 16:17:58 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 27:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context.prev = 27;
|
|
|
|
|
_context.t0 = _context['catch'](20);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 30:
|
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
}, _callee, this, [[20, 27]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
function add(_x) {
|
|
|
|
|
return _ref.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return add;
|
|
|
|
|
}()
|
2017-07-10 11:56:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加项目
|
|
|
|
|
* @interface /project/add_member
|
|
|
|
|
* @method POST
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} id 项目id,不能为空
|
|
|
|
|
* @param {member_uid} uid 项目成员uid,不能为空
|
|
|
|
|
* @returns {Object}
|
|
|
|
|
* @example ./api/project/add_member.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'addMember',
|
|
|
|
|
value: function () {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var params, check, result;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
switch (_context2.prev = _context2.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
|
|
|
|
params = ctx.request.body;
|
|
|
|
|
|
|
|
|
|
if (params.member_uid) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context2.next = 3;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目成员uid不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
if (params.id) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context2.next = 5;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 5:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context2.next = 7;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.checkMemberRepeat(params.id, params.member_uid);
|
|
|
|
|
|
|
|
|
|
case 7:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
check = _context2.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
if (!(check > 0)) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context2.next = 10;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目成员已存在'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 10:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context2.prev = 10;
|
|
|
|
|
_context2.next = 13;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.addMember(params.id, params.member_uid);
|
|
|
|
|
|
|
|
|
|
case 13:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context2.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context2.next = 20;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 17:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context2.prev = 17;
|
|
|
|
|
_context2.t0 = _context2['catch'](10);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context2.t0.message);
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 20:
|
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context2.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
}, _callee2, this, [[10, 17]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
function addMember(_x2) {
|
|
|
|
|
return _ref2.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return addMember;
|
|
|
|
|
}()
|
2017-07-10 11:56:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加项目
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'delMember',
|
|
|
|
|
value: function () {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var params, check, result;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee3$(_context3) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
switch (_context3.prev = _context3.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
|
|
|
|
params = ctx.request.body;
|
|
|
|
|
|
|
|
|
|
if (params.member_uid) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context3.next = 3;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目成员uid不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
if (params.id) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context3.next = 5;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 5:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context3.next = 7;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.checkMemberRepeat(params.id, params.member_uid);
|
|
|
|
|
|
|
|
|
|
case 7:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
check = _context3.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
if (!(check === 0)) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context3.next = 10;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目成员不存在'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 10:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context3.prev = 10;
|
|
|
|
|
_context3.next = 13;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.delMember(params.id, params.member_uid);
|
|
|
|
|
|
|
|
|
|
case 13:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context3.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context3.next = 20;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 17:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context3.prev = 17;
|
|
|
|
|
_context3.t0 = _context3['catch'](10);
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 20:
|
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context3.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
}, _callee3, this, [[10, 17]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
function delMember(_x3) {
|
|
|
|
|
return _ref3.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return delMember;
|
|
|
|
|
}()
|
2017-07-10 11:56:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加项目
|
|
|
|
|
* @interface /project/get
|
|
|
|
|
* @method GET
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} id 项目id,不能为空
|
|
|
|
|
* @returns {Object}
|
|
|
|
|
* @example ./api/project/get.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'get',
|
|
|
|
|
value: function () {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var params, result;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
switch (_context4.prev = _context4.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
|
|
|
|
params = ctx.request.query;
|
|
|
|
|
|
|
|
|
|
if (params.id) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context4.next = 3;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 3:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context4.prev = 3;
|
|
|
|
|
_context4.next = 6;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.get(params.id);
|
|
|
|
|
|
|
|
|
|
case 6:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context4.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context4.next = 13;
|
2017-07-05 16:17:58 +08:00
|
|
|
|
break;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 10:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context4.prev = 10;
|
|
|
|
|
_context4.t0 = _context4['catch'](3);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context4.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
}, _callee4, this, [[3, 10]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
function get(_x4) {
|
|
|
|
|
return _ref4.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return get;
|
|
|
|
|
}()
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取项目列表
|
|
|
|
|
* @interface /project/list
|
|
|
|
|
* @method GET
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} group_id 项目group_id,不能为空
|
|
|
|
|
* @returns {Object}
|
|
|
|
|
* @example ./api/project/list.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'list',
|
|
|
|
|
value: function () {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
2017-07-06 20:53:26 +08:00
|
|
|
|
var group_id, result;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
switch (_context5.prev = _context5.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
2017-07-06 20:53:26 +08:00
|
|
|
|
group_id = ctx.request.query.group_id;
|
|
|
|
|
|
|
|
|
|
if (group_id) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context5.next = 3;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-06 20:53:26 +08:00
|
|
|
|
case 3:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context5.prev = 3;
|
|
|
|
|
_context5.next = 6;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
return this.Model.list(group_id);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-06 20:53:26 +08:00
|
|
|
|
case 6:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context5.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context5.next = 13;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-07-06 20:53:26 +08:00
|
|
|
|
case 10:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context5.prev = 10;
|
|
|
|
|
_context5.t0 = _context5['catch'](3);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
|
|
|
|
|
2017-07-06 20:53:26 +08:00
|
|
|
|
case 13:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context5.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
}, _callee5, this, [[3, 10]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
function list(_x5) {
|
|
|
|
|
return _ref5.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}()
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除项目
|
|
|
|
|
* @interface /project/del
|
|
|
|
|
* @method POST
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} id 项目id,不能为空
|
|
|
|
|
* @returns {Object}
|
|
|
|
|
* @example ./api/project/del.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'del',
|
|
|
|
|
value: function () {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
2017-07-10 20:02:44 +08:00
|
|
|
|
var id, interfaceInst, count, result;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
switch (_context6.prev = _context6.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context6.prev = 0;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
id = ctx.request.body.id;
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
if (id) {
|
|
|
|
|
_context6.next = 4;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 4:
|
2017-07-10 20:02:44 +08:00
|
|
|
|
interfaceInst = _yapi2.default.getInst(_interface2.default);
|
|
|
|
|
_context6.next = 7;
|
|
|
|
|
return interfaceInst.countByProjectId(id);
|
|
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
|
count = _context6.sent;
|
|
|
|
|
|
|
|
|
|
if (!(count > 0)) {
|
|
|
|
|
_context6.next = 10;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
|
|
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
|
_context6.next = 12;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return this.jungeProjectAuth(id);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 12:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context6.t0 = _context6.sent;
|
|
|
|
|
|
|
|
|
|
if (!(_context6.t0 !== true)) {
|
2017-07-10 20:02:44 +08:00
|
|
|
|
_context6.next = 15;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 15:
|
|
|
|
|
_context6.next = 17;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return this.Model.del(id);
|
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 17:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context6.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-07-10 20:02:44 +08:00
|
|
|
|
_context6.next = 24;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 21:
|
|
|
|
|
_context6.prev = 21;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context6.t1 = _context6['catch'](0);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 24:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context6.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
}
|
2017-07-10 20:02:44 +08:00
|
|
|
|
}, _callee6, this, [[0, 21]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
function del(_x6) {
|
|
|
|
|
return _ref6.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return del;
|
|
|
|
|
}()
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 编辑项目
|
|
|
|
|
* @interface /project/up
|
|
|
|
|
* @method GET
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} id 项目id,不能为空
|
|
|
|
|
* @param {String} name 项目名称,不能为空
|
|
|
|
|
* @param {String} basepath 项目基本路径,不能为空
|
|
|
|
|
* @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
|
|
|
|
|
* @param {String} [desc] 项目描述
|
2017-07-10 20:02:44 +08:00
|
|
|
|
* @param {Array} [env] 项目环境配置
|
|
|
|
|
* @param {String} [env[].name] 环境名称
|
|
|
|
|
* @param {String} [env[].host] 环境域名
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @returns {Object}
|
|
|
|
|
* @example ./api/project/up.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'up',
|
|
|
|
|
value: function () {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
|
|
|
|
var id, params, checkRepeat, checkRepeatDomain, data, result;
|
|
|
|
|
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
switch (_context7.prev = _context7.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context7.prev = 0;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
id = ctx.request.body.id;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
params = ctx.request.body;
|
|
|
|
|
_context7.next = 5;
|
|
|
|
|
return this.jungeMemberAuth(id, this.getUid());
|
|
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
_context7.t0 = _context7.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
if (!(_context7.t0 !== true)) {
|
|
|
|
|
_context7.next = 8;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
case 8:
|
|
|
|
|
if (!params.name) {
|
|
|
|
|
_context7.next = 14;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context7.next = 11;
|
|
|
|
|
return this.Model.checkNameRepeat(params.name);
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
case 11:
|
|
|
|
|
checkRepeat = _context7.sent;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
|
|
|
|
if (!(checkRepeat > 0)) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context7.next = 14;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
break;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
|
|
|
|
case 14:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
if (!(params.basepath && params.prd_host)) {
|
|
|
|
|
_context7.next = 20;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context7.next = 17;
|
|
|
|
|
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
case 17:
|
|
|
|
|
checkRepeatDomain = _context7.sent;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
|
|
|
|
if (!(checkRepeatDomain > 0)) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context7.next = 20;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
case 20:
|
2017-07-06 20:53:26 +08:00
|
|
|
|
data = {
|
|
|
|
|
uid: this.getUid(),
|
2017-07-10 11:56:53 +08:00
|
|
|
|
up_time: _yapi2.default.commons.time()
|
2017-07-06 20:53:26 +08:00
|
|
|
|
};
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.env) data.env = params.env;
|
|
|
|
|
|
|
|
|
|
_context7.next = 27;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.up(id, data);
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
case 27:
|
|
|
|
|
result = _context7.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context7.next = 34;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
case 31:
|
|
|
|
|
_context7.prev = 31;
|
|
|
|
|
_context7.t1 = _context7['catch'](0);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t1.message);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
case 34:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context7.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
}, _callee7, this, [[0, 31]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
function up(_x7) {
|
|
|
|
|
return _ref7.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return up;
|
|
|
|
|
}()
|
|
|
|
|
}]);
|
|
|
|
|
return projectController;
|
|
|
|
|
}(_base2.default);
|
|
|
|
|
|
|
|
|
|
module.exports = projectController;
|