2017-07-05 16:17:58 +08:00
|
|
|
|
'use strict';
|
|
|
|
|
|
2017-08-10 12:14:35 +08:00
|
|
|
|
var _stringify = require('babel-runtime/core-js/json/stringify');
|
|
|
|
|
|
|
|
|
|
var _stringify2 = _interopRequireDefault(_stringify);
|
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
|
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-14 16:41:14 +08:00
|
|
|
|
var _group = require('../models/group');
|
|
|
|
|
|
|
|
|
|
var _group2 = _interopRequireDefault(_group);
|
|
|
|
|
|
2017-07-18 16:46:19 +08:00
|
|
|
|
var _commons = require('../utils/commons.js');
|
|
|
|
|
|
|
|
|
|
var _commons2 = _interopRequireDefault(_commons);
|
|
|
|
|
|
2017-07-20 15:26:26 +08:00
|
|
|
|
var _user = require('../models/user.js');
|
|
|
|
|
|
|
|
|
|
var _user2 = _interopRequireDefault(_user);
|
|
|
|
|
|
2017-08-11 17:49:47 +08:00
|
|
|
|
var _log = require('../models/log.js');
|
|
|
|
|
|
|
|
|
|
var _log2 = _interopRequireDefault(_log);
|
|
|
|
|
|
2017-08-10 12:14:35 +08:00
|
|
|
|
var _mockjs = require('mockjs');
|
|
|
|
|
|
|
|
|
|
var _mockjs2 = _interopRequireDefault(_mockjs);
|
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
2017-08-10 12:14:35 +08:00
|
|
|
|
var send = require('koa-send');
|
|
|
|
|
|
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);
|
2017-07-14 16:41:14 +08:00
|
|
|
|
_this.groupModel = _yapi2.default.getInst(_group2.default);
|
2017-08-11 17:49:47 +08:00
|
|
|
|
_this.logModel = _yapi2.default.getInst(_log2.default);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return _this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 16:44:41 +08:00
|
|
|
|
(0, _createClass3.default)(projectController, [{
|
|
|
|
|
key: 'handleBasepath',
|
|
|
|
|
value: function handleBasepath(basepath) {
|
2017-08-01 15:37:07 +08:00
|
|
|
|
if (!basepath) return "";
|
|
|
|
|
if (basepath === '/') return "";
|
2017-07-20 16:44:41 +08:00
|
|
|
|
if (basepath[0] !== '/') basepath = '/' + basepath;
|
|
|
|
|
if (basepath[basepath.length - 1] === '/') basepath = basepath.substr(0, basepath.length - 1);
|
2017-07-24 19:35:15 +08:00
|
|
|
|
if (!_yapi2.default.commons.verifyPath(basepath)) {
|
2017-07-20 16:44:41 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return basepath;
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
key: 'verifyDomain',
|
|
|
|
|
value: function verifyDomain(domain) {
|
|
|
|
|
if (!domain) return false;
|
2017-07-25 21:51:14 +08:00
|
|
|
|
if (/^[a-zA-Z0-9\-_\.]+?\.[a-zA-Z0-9\-_\.]*?[a-zA-Z]{2,6}$/.test(domain)) {
|
2017-07-20 16:44:41 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-20 16:44:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加项目分组
|
|
|
|
|
* @interface /project/add
|
|
|
|
|
* @method POST
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {String} name 项目名称,不能为空
|
|
|
|
|
* @param {String} basepath 项目基本路径,不能为空
|
|
|
|
|
* @param {Number} group_id 项目分组id,不能为空
|
2017-08-11 17:24:50 +08:00
|
|
|
|
* @param {String} project_type private public
|
2017-07-24 19:35:15 +08:00
|
|
|
|
* @param {String} [desc] 项目描述
|
|
|
|
|
* @returns {Object}
|
2017-07-20 16:44:41 +08:00
|
|
|
|
* @example ./api/project/add.json
|
|
|
|
|
*/
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-20 16:44:41 +08:00
|
|
|
|
}, {
|
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-08-15 12:08:59 +08:00
|
|
|
|
var params, checkRepeat, data, result, username;
|
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;
|
|
|
|
|
|
2017-07-26 14:22:59 +08:00
|
|
|
|
params = _yapi2.default.commons.handleParams(params, {
|
|
|
|
|
name: 'string',
|
|
|
|
|
basepath: 'string',
|
|
|
|
|
group_id: 'number',
|
|
|
|
|
desc: 'string'
|
|
|
|
|
});
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context.next = 4;
|
|
|
|
|
return this.checkAuth(params.group_id, 'group', 'edit');
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
_context.t0 = _context.sent;
|
|
|
|
|
|
|
|
|
|
if (!(_context.t0 !== true)) {
|
|
|
|
|
_context.next = 7;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
|
|
|
|
|
|
|
|
|
case 7:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
if (params.group_id) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context.next = 9;
|
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
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
case 9:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
if (params.name) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context.next = 11;
|
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
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
case 11:
|
|
|
|
|
_context.next = 13;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.checkNameRepeat(params.name);
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
case 13:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
checkRepeat = _context.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
if (!(checkRepeat > 0)) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context.next = 16;
|
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
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
case 16:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-01 15:37:07 +08:00
|
|
|
|
params.basepath = params.basepath || '';
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-21 10:03:34 +08:00
|
|
|
|
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
2017-08-15 12:08:59 +08:00
|
|
|
|
_context.next = 19;
|
2017-07-20 16:44:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-15 12:08:59 +08:00
|
|
|
|
case 19:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
data = {
|
|
|
|
|
name: params.name,
|
|
|
|
|
desc: params.desc,
|
|
|
|
|
basepath: params.basepath,
|
2017-08-08 14:45:19 +08:00
|
|
|
|
members: [],
|
2017-08-09 16:16:35 +08:00
|
|
|
|
project_type: params.project_type || 'private',
|
2017-07-06 19:21:54 +08:00
|
|
|
|
uid: this.getUid(),
|
|
|
|
|
group_id: params.group_id,
|
|
|
|
|
add_time: _yapi2.default.commons.time(),
|
|
|
|
|
up_time: _yapi2.default.commons.time()
|
|
|
|
|
};
|
2017-08-15 12:08:59 +08:00
|
|
|
|
_context.prev = 20;
|
|
|
|
|
_context.next = 23;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.save(data);
|
|
|
|
|
|
2017-08-15 12:08:59 +08:00
|
|
|
|
case 23:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context.sent;
|
2017-08-11 17:49:47 +08:00
|
|
|
|
username = this.getUsername();
|
2017-08-16 17:12:01 +08:00
|
|
|
|
|
|
|
|
|
_yapi2.default.commons.saveLog({
|
2017-08-11 17:49:47 +08:00
|
|
|
|
content: '\u7528\u6237' + username + '\u6DFB\u52A0\u4E86\u9879\u76EE' + params.name,
|
|
|
|
|
type: 'project',
|
|
|
|
|
uid: this.getUid(),
|
|
|
|
|
username: username,
|
|
|
|
|
typeid: params.group_id
|
|
|
|
|
});
|
2017-07-06 19:21:54 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_context.next = 32;
|
2017-07-05 16:17:58 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 29:
|
|
|
|
|
_context.prev = 29;
|
2017-08-15 12:08:59 +08:00
|
|
|
|
_context.t1 = _context['catch'](20);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t1.message);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 32:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-16 17:12:01 +08:00
|
|
|
|
}, _callee, this, [[20, 29]]);
|
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
|
|
|
|
/**
|
2017-07-18 16:46:19 +08:00
|
|
|
|
* 添加项目
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @interface /project/add_member
|
|
|
|
|
* @method POST
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} id 项目id,不能为空
|
2017-07-14 16:41:14 +08:00
|
|
|
|
* @param {String} member_uid 项目成员uid,不能为空
|
2017-07-24 19:35:15 +08:00
|
|
|
|
* @returns {Object}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @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-08-11 17:49:47 +08:00
|
|
|
|
var params, check, userdata, result, username;
|
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-08-08 19:18:12 +08:00
|
|
|
|
return this.checkAuth(params.id, 'project', 'edit');
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 7:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context2.t0 = _context2.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
if (!(_context2.t0 !== true)) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
_context2.next = 10;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 10:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context2.next = 12;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return this.Model.checkMemberRepeat(params.id, params.member_uid);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
case 12:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
check = _context2.sent;
|
|
|
|
|
|
|
|
|
|
if (!(check > 0)) {
|
|
|
|
|
_context2.next = 15;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目成员已存在'));
|
|
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
|
_context2.next = 17;
|
|
|
|
|
return this.getUserdata(params.member_uid);
|
|
|
|
|
|
|
|
|
|
case 17:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
userdata = _context2.sent;
|
|
|
|
|
|
|
|
|
|
if (!(userdata === null)) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context2.next = 20;
|
2017-08-08 14:45:19 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '成员uid不存在'));
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
case 20:
|
|
|
|
|
_context2.prev = 20;
|
|
|
|
|
_context2.next = 23;
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return this.Model.addMember(params.id, userdata);
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
case 23:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context2.sent;
|
2017-08-11 17:49:47 +08:00
|
|
|
|
username = this.getUsername();
|
2017-08-16 17:12:01 +08:00
|
|
|
|
|
|
|
|
|
_yapi2.default.commons.saveLog({
|
2017-08-11 17:49:47 +08:00
|
|
|
|
content: '\u7528\u6237' + username + '\u6DFB\u52A0\u4E86\u9879\u76EE\u6210\u5458' + userdata.username,
|
|
|
|
|
type: 'project',
|
|
|
|
|
uid: this.getUid(),
|
|
|
|
|
username: username,
|
|
|
|
|
typeid: params.id
|
|
|
|
|
});
|
2017-07-06 19:21:54 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_context2.next = 32;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 29:
|
|
|
|
|
_context2.prev = 29;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context2.t1 = _context2['catch'](20);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context2.t1.message);
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 32:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context2.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-16 17:12:01 +08:00
|
|
|
|
}, _callee2, this, [[20, 29]]);
|
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
|
|
|
|
/**
|
2017-07-18 16:46:19 +08:00
|
|
|
|
* 添加项目
|
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,不能为空
|
2017-07-24 19:35:15 +08:00
|
|
|
|
* @returns {Object}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @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-08-16 17:12:01 +08:00
|
|
|
|
var params, check, result, username, project, member;
|
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-08-08 19:18:12 +08:00
|
|
|
|
_context3.next = 12;
|
|
|
|
|
return this.checkAuth(params.id, 'project', 'danger');
|
|
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
|
_context3.t0 = _context3.sent;
|
|
|
|
|
|
|
|
|
|
if (!(_context3.t0 !== true)) {
|
|
|
|
|
_context3.next = 15;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
|
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
|
_context3.prev = 15;
|
|
|
|
|
_context3.next = 18;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.delMember(params.id, params.member_uid);
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
case 18:
|
2017-07-10 11:56:53 +08:00
|
|
|
|
result = _context3.sent;
|
2017-08-11 17:49:47 +08:00
|
|
|
|
username = this.getUsername();
|
|
|
|
|
_context3.next = 22;
|
|
|
|
|
return this.Model.get(params.id);
|
|
|
|
|
|
|
|
|
|
case 22:
|
|
|
|
|
project = _context3.sent;
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_context3.next = 25;
|
|
|
|
|
return _yapi2.default.getInst(_user2.default).findById(params.member_uid);
|
2017-08-11 17:49:47 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 25:
|
|
|
|
|
member = _context3.sent;
|
2017-08-11 17:49:47 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_yapi2.default.commons.saveLog({
|
|
|
|
|
content: '\u7528\u6237' + username + '\u5220\u9664\u4E86\u9879\u76EE' + project.name + '\u4E2D\u7684\u6210\u5458' + member.username,
|
2017-08-11 17:49:47 +08:00
|
|
|
|
type: 'project',
|
|
|
|
|
uid: this.getUid(),
|
|
|
|
|
username: username,
|
|
|
|
|
typeid: params.id
|
|
|
|
|
});
|
2017-07-06 19:21:54 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_context3.next = 33;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 30:
|
|
|
|
|
_context3.prev = 30;
|
|
|
|
|
_context3.t1 = _context3['catch'](15);
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t1.message);
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 33:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return _context3.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-16 17:12:01 +08:00
|
|
|
|
}, _callee3, this, [[15, 30]]);
|
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-08-08 14:45:19 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'getUserdata',
|
|
|
|
|
value: function () {
|
|
|
|
|
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(uid, role) {
|
|
|
|
|
var userInst, userData;
|
|
|
|
|
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
|
|
|
|
while (1) {
|
|
|
|
|
switch (_context4.prev = _context4.next) {
|
|
|
|
|
case 0:
|
|
|
|
|
role = role || 'dev';
|
|
|
|
|
userInst = _yapi2.default.getInst(_user2.default);
|
|
|
|
|
_context4.next = 4;
|
|
|
|
|
return userInst.findById(uid);
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
userData = _context4.sent;
|
|
|
|
|
|
|
|
|
|
if (userData) {
|
|
|
|
|
_context4.next = 7;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context4.abrupt('return', null);
|
|
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
|
return _context4.abrupt('return', {
|
|
|
|
|
role: role,
|
|
|
|
|
uid: userData._id,
|
|
|
|
|
username: userData.username,
|
|
|
|
|
email: userData.email
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
|
case 'end':
|
|
|
|
|
return _context4.stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, _callee4, this);
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
function getUserdata(_x4, _x5) {
|
|
|
|
|
return _ref4.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getUserdata;
|
|
|
|
|
}()
|
2017-07-14 17:37:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取项目成员列表
|
2017-07-18 15:13:47 +08:00
|
|
|
|
* @interface /project/get_member_list
|
2017-07-14 17:37:26 +08:00
|
|
|
|
* @method GET
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} id 项目id,不能为空
|
|
|
|
|
* @return {Object}
|
|
|
|
|
* @example ./api/project/get_member_list.json
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
key: 'getMemberList',
|
|
|
|
|
value: function () {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
|
|
|
|
var params, project;
|
|
|
|
|
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
2017-07-14 17:37:26 +08:00
|
|
|
|
while (1) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
switch (_context5.prev = _context5.next) {
|
2017-07-14 17:37:26 +08:00
|
|
|
|
case 0:
|
|
|
|
|
params = ctx.request.query;
|
|
|
|
|
|
|
|
|
|
if (params.id) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context5.next = 3;
|
2017-07-14 17:37:26 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
2017-07-14 17:37:26 +08:00
|
|
|
|
|
|
|
|
|
case 3:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context5.prev = 3;
|
|
|
|
|
_context5.next = 6;
|
2017-07-14 17:37:26 +08:00
|
|
|
|
return this.Model.get(params.id);
|
|
|
|
|
|
|
|
|
|
case 6:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
project = _context5.sent;
|
2017-07-14 17:37:26 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(project.members);
|
|
|
|
|
_context5.next = 13;
|
2017-07-14 17:37:26 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
case 10:
|
|
|
|
|
_context5.prev = 10;
|
|
|
|
|
_context5.t0 = _context5['catch'](3);
|
2017-07-14 17:37:26 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message);
|
2017-07-14 17:37:26 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
case 13:
|
2017-07-14 17:37:26 +08:00
|
|
|
|
case 'end':
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context5.stop();
|
2017-07-14 17:37:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-08 14:45:19 +08:00
|
|
|
|
}, _callee5, this, [[3, 10]]);
|
2017-07-14 17:37:26 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
function getMemberList(_x6) {
|
|
|
|
|
return _ref5.apply(this, arguments);
|
2017-07-14 17:37:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getMemberList;
|
|
|
|
|
}()
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加项目
|
|
|
|
|
* @interface /project/get
|
|
|
|
|
* @method GET
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} id 项目id,不能为空
|
2017-07-24 19:35:15 +08:00
|
|
|
|
* @returns {Object}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @example ./api/project/get.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'get',
|
|
|
|
|
value: function () {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
var params, result;
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
switch (_context6.prev = _context6.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
|
|
|
|
params = ctx.request.query;
|
|
|
|
|
|
|
|
|
|
if (params.id) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context6.next = 3;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 3:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context6.prev = 3;
|
|
|
|
|
_context6.next = 6;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
return this.Model.get(params.id);
|
|
|
|
|
|
|
|
|
|
case 6:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
result = _context6.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context6.next = 13;
|
2017-07-05 16:17:58 +08:00
|
|
|
|
break;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 10:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context6.prev = 10;
|
|
|
|
|
_context6.t0 = _context6['catch'](3);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
|
case 'end':
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context6.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
}
|
2017-08-08 14:45:19 +08:00
|
|
|
|
}, _callee6, this, [[3, 10]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
function get(_x7) {
|
|
|
|
|
return _ref6.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,不能为空
|
2017-07-24 19:35:15 +08:00
|
|
|
|
* @returns {Object}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @example ./api/project/list.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'list',
|
|
|
|
|
value: function () {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
2017-08-09 16:16:35 +08:00
|
|
|
|
var group_id, auth, result, uids, _users, users;
|
2017-07-20 15:26:26 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
switch (_context7.prev = _context7.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
2017-08-09 16:16:35 +08:00
|
|
|
|
group_id = ctx.request.query.group_id;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
|
|
|
|
if (group_id) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context7.next = 3;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context7.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-08-09 16:16:35 +08:00
|
|
|
|
_context7.next = 5;
|
|
|
|
|
return this.checkAuth(group_id, 'group', 'edit');
|
|
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
auth = _context7.sent;
|
|
|
|
|
_context7.prev = 6;
|
|
|
|
|
_context7.next = 9;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return this.Model.list(group_id, auth);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-09 16:16:35 +08:00
|
|
|
|
case 9:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
result = _context7.sent;
|
2017-07-20 15:26:26 +08:00
|
|
|
|
uids = [];
|
|
|
|
|
|
|
|
|
|
result.forEach(function (item) {
|
2017-07-24 16:28:58 +08:00
|
|
|
|
if (uids.indexOf(item.uid) === -1) {
|
2017-07-20 15:26:26 +08:00
|
|
|
|
uids.push(item.uid);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_users = {};
|
2017-08-09 16:16:35 +08:00
|
|
|
|
_context7.next = 15;
|
2017-07-20 15:26:26 +08:00
|
|
|
|
return _yapi2.default.getInst(_user2.default).findByUids(uids);
|
|
|
|
|
|
2017-08-09 16:16:35 +08:00
|
|
|
|
case 15:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
users = _context7.sent;
|
2017-07-20 15:26:26 +08:00
|
|
|
|
|
|
|
|
|
users.forEach(function (item) {
|
|
|
|
|
_users[item._id] = item;
|
|
|
|
|
});
|
2017-07-18 15:13:47 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn({
|
2017-08-15 17:55:52 +08:00
|
|
|
|
list: result
|
2017-07-18 15:13:47 +08:00
|
|
|
|
});
|
2017-08-09 16:16:35 +08:00
|
|
|
|
_context7.next = 23;
|
2017-07-18 15:13:47 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-08-09 16:16:35 +08:00
|
|
|
|
case 20:
|
|
|
|
|
_context7.prev = 20;
|
|
|
|
|
_context7.t0 = _context7['catch'](6);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t0.message);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-09 16:16:35 +08:00
|
|
|
|
case 23:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context7.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
}
|
2017-08-09 16:16:35 +08:00
|
|
|
|
}, _callee7, this, [[6, 20]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
function list(_x8) {
|
|
|
|
|
return _ref7.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,不能为空
|
2017-07-24 19:35:15 +08:00
|
|
|
|
* @returns {Object}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @example ./api/project/del.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'del',
|
|
|
|
|
value: function () {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
var _id, interfaceInst, count, result;
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
switch (_context8.prev = _context8.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.prev = 0;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_id = ctx.request.body.id;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
if (_id) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.next = 4;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context8.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);
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.next = 7;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return interfaceInst.countByProjectId(_id);
|
2017-07-10 20:02:44 +08:00
|
|
|
|
|
|
|
|
|
case 7:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
count = _context8.sent;
|
2017-07-10 20:02:44 +08:00
|
|
|
|
|
|
|
|
|
if (!(count > 0)) {
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.next = 10;
|
2017-07-10 20:02:44 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
|
2017-07-10 20:02:44 +08:00
|
|
|
|
|
|
|
|
|
case 10:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.next = 12;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return this.checkAuth(_id, 'project', 'danger');
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 12:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.t0 = _context8.sent;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
if (!(_context8.t0 !== true)) {
|
|
|
|
|
_context8.next = 15;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 15:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.next = 17;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return this.Model.del(_id);
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 17:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
result = _context8.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.next = 24;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 21:
|
2017-08-08 14:45:19 +08:00
|
|
|
|
_context8.prev = 21;
|
|
|
|
|
_context8.t1 = _context8['catch'](0);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
|
case 24:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-08-08 14:45:19 +08:00
|
|
|
|
return _context8.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
}
|
2017-08-08 14:45:19 +08:00
|
|
|
|
}, _callee8, this, [[0, 21]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
|
function del(_x9) {
|
|
|
|
|
return _ref8.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return del;
|
|
|
|
|
}()
|
2017-08-08 19:18:12 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'changeMemberRole',
|
|
|
|
|
value: function () {
|
|
|
|
|
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
2017-08-16 17:12:01 +08:00
|
|
|
|
var params, groupInst, check, result, username, project, member;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
|
|
|
|
while (1) {
|
|
|
|
|
switch (_context9.prev = _context9.next) {
|
|
|
|
|
case 0:
|
|
|
|
|
params = ctx.request.body;
|
|
|
|
|
groupInst = _yapi2.default.getInst(_group2.default);
|
|
|
|
|
|
|
|
|
|
if (params.member_uid) {
|
|
|
|
|
_context9.next = 4;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员uid不能为空'));
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
if (params.id) {
|
|
|
|
|
_context9.next = 6;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组id不能为空'));
|
|
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
_context9.next = 8;
|
|
|
|
|
return groupInst.checkMemberRepeat(params.id, params.member_uid);
|
|
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
|
check = _context9.sent;
|
|
|
|
|
|
|
|
|
|
if (!(check === 0)) {
|
|
|
|
|
_context9.next = 11;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员不存在'));
|
|
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
|
_context9.next = 13;
|
|
|
|
|
return this.checkAuth(id, 'group', 'danger');
|
|
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
|
_context9.t0 = _context9.sent;
|
|
|
|
|
|
|
|
|
|
if (!(_context9.t0 !== true)) {
|
|
|
|
|
_context9.next = 16;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
|
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
|
|
|
|
|
|
params.role = params.role === 'owner' ? 'owner' : 'dev';
|
|
|
|
|
|
|
|
|
|
_context9.prev = 17;
|
|
|
|
|
_context9.next = 20;
|
|
|
|
|
return groupInst.changeMemberRole(params.id, params.member_uid, params.role);
|
|
|
|
|
|
|
|
|
|
case 20:
|
|
|
|
|
result = _context9.sent;
|
2017-08-11 17:49:47 +08:00
|
|
|
|
username = this.getUsername();
|
|
|
|
|
_context9.next = 24;
|
|
|
|
|
return this.Model.get(params.id);
|
|
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
|
project = _context9.sent;
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_context9.next = 27;
|
|
|
|
|
return _yapi2.default.getInst(_user2.default).findByUids(params.member_uid);
|
2017-08-11 17:49:47 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 27:
|
|
|
|
|
member = _context9.sent;
|
2017-08-11 17:49:47 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_yapi2.default.commons.saveLog({
|
|
|
|
|
content: '\u7528\u6237' + username + '\u4FEE\u6539\u4E86\u9879\u76EE' + project.name + '\u4E2D\u6210\u5458' + member.username + '\u7684\u89D2\u8272\u4E3A' + params.role,
|
2017-08-11 17:49:47 +08:00
|
|
|
|
type: 'project',
|
|
|
|
|
uid: this.getUid(),
|
|
|
|
|
username: username,
|
|
|
|
|
typeid: params.id
|
|
|
|
|
});
|
2017-08-08 19:18:12 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_context9.next = 35;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 32:
|
|
|
|
|
_context9.prev = 32;
|
|
|
|
|
_context9.t1 = _context9['catch'](17);
|
2017-08-08 19:18:12 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t1.message);
|
2017-08-08 19:18:12 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 35:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
case 'end':
|
|
|
|
|
return _context9.stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-16 17:12:01 +08:00
|
|
|
|
}, _callee9, this, [[17, 32]]);
|
2017-08-08 19:18:12 +08:00
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
function changeMemberRole(_x10) {
|
|
|
|
|
return _ref9.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return changeMemberRole;
|
|
|
|
|
}()
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 编辑项目
|
|
|
|
|
* @interface /project/up
|
2017-07-18 16:46:19 +08:00
|
|
|
|
* @method POST
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {Number} id 项目id,不能为空
|
|
|
|
|
* @param {String} name 项目名称,不能为空
|
|
|
|
|
* @param {String} basepath 项目基本路径,不能为空
|
2017-07-24 19:35:15 +08:00
|
|
|
|
* @param {String} [desc] 项目描述
|
2017-07-10 20:02:44 +08:00
|
|
|
|
* @param {Array} [env] 项目环境配置
|
|
|
|
|
* @param {String} [env[].name] 环境名称
|
2017-07-24 11:24:08 +08:00
|
|
|
|
* @param {String} [env[].domain] 环境域名
|
2017-07-24 19:35:15 +08:00
|
|
|
|
* @returns {Object}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
* @example ./api/project/up.json
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: 'up',
|
|
|
|
|
value: function () {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
2017-08-15 12:08:59 +08:00
|
|
|
|
var _id2, params, projectData, checkRepeat, data, result, username;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
|
|
|
|
|
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
while (1) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
switch (_context10.prev = _context10.next) {
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 0:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context10.prev = 0;
|
|
|
|
|
_id2 = ctx.request.body.id;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
params = ctx.request.body;
|
2017-07-20 15:26:26 +08:00
|
|
|
|
|
2017-08-01 15:37:07 +08:00
|
|
|
|
params.basepath = params.basepath || '';
|
2017-07-26 14:22:59 +08:00
|
|
|
|
params = _yapi2.default.commons.handleParams(params, {
|
|
|
|
|
name: 'string',
|
|
|
|
|
basepath: 'string',
|
|
|
|
|
group_id: 'number',
|
|
|
|
|
desc: 'string'
|
|
|
|
|
});
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
if (_id2) {
|
|
|
|
|
_context10.next = 7;
|
2017-07-20 15:26:26 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
2017-08-01 15:37:07 +08:00
|
|
|
|
case 7:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context10.next = 9;
|
|
|
|
|
return this.checkAuth(_id2, 'project', 'edit');
|
2017-07-20 15:26:26 +08:00
|
|
|
|
|
2017-08-01 15:37:07 +08:00
|
|
|
|
case 9:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context10.t0 = _context10.sent;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
if (!(_context10.t0 !== true)) {
|
|
|
|
|
_context10.next = 12;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-01 15:37:07 +08:00
|
|
|
|
case 12:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context10.next = 14;
|
|
|
|
|
return this.Model.get(_id2);
|
2017-07-20 15:26:26 +08:00
|
|
|
|
|
2017-08-01 15:37:07 +08:00
|
|
|
|
case 14:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
projectData = _context10.sent;
|
2017-07-20 15:26:26 +08:00
|
|
|
|
|
2017-07-25 21:51:14 +08:00
|
|
|
|
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context10.next = 17;
|
2017-07-20 16:44:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
2017-07-20 16:44:41 +08:00
|
|
|
|
|
2017-08-01 15:37:07 +08:00
|
|
|
|
case 17:
|
2017-07-20 16:44:41 +08:00
|
|
|
|
|
2017-07-20 15:26:26 +08:00
|
|
|
|
if (projectData.name === params.name) {
|
|
|
|
|
delete params.name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
|
if (!params.name) {
|
2017-08-15 12:08:59 +08:00
|
|
|
|
_context10.next = 24;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-15 12:08:59 +08:00
|
|
|
|
_context10.next = 21;
|
2017-07-10 11:56:53 +08:00
|
|
|
|
return this.Model.checkNameRepeat(params.name);
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
2017-08-15 12:08:59 +08:00
|
|
|
|
case 21:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
checkRepeat = _context10.sent;
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
|
|
|
|
if (!(checkRepeat > 0)) {
|
2017-08-15 12:08:59 +08:00
|
|
|
|
_context10.next = 24;
|
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-08-08 19:18:12 +08:00
|
|
|
|
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
2017-07-06 20:53:26 +08:00
|
|
|
|
|
2017-08-15 12:08:59 +08:00
|
|
|
|
case 24:
|
2017-07-06 20:53:26 +08:00
|
|
|
|
data = {
|
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;
|
2017-08-15 12:08:59 +08:00
|
|
|
|
if (params.basepath) {
|
2017-07-10 11:56:53 +08:00
|
|
|
|
data.basepath = params.basepath;
|
|
|
|
|
}
|
|
|
|
|
if (params.env) data.env = params.env;
|
|
|
|
|
|
2017-08-15 12:08:59 +08:00
|
|
|
|
_context10.next = 31;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return this.Model.up(_id2, data);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-15 12:08:59 +08:00
|
|
|
|
case 31:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
result = _context10.sent;
|
2017-08-11 17:49:47 +08:00
|
|
|
|
username = this.getUsername();
|
2017-08-16 17:12:01 +08:00
|
|
|
|
|
|
|
|
|
_yapi2.default.commons.saveLog({
|
|
|
|
|
content: '\u7528\u6237' + username + '\u66F4\u65B0\u4E86\u9879\u76EE' + projectData.name,
|
2017-08-11 17:49:47 +08:00
|
|
|
|
type: 'project',
|
|
|
|
|
uid: this.getUid(),
|
|
|
|
|
username: username,
|
|
|
|
|
typeid: _id2
|
|
|
|
|
});
|
2017-07-06 19:21:54 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(result);
|
2017-08-16 17:12:01 +08:00
|
|
|
|
_context10.next = 40;
|
2017-07-06 19:21:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 37:
|
|
|
|
|
_context10.prev = 37;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context10.t1 = _context10['catch'](0);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context10.t1.message);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
2017-08-16 17:12:01 +08:00
|
|
|
|
case 40:
|
2017-07-06 19:21:54 +08:00
|
|
|
|
case 'end':
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context10.stop();
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
}
|
2017-08-16 17:12:01 +08:00
|
|
|
|
}, _callee10, this, [[0, 37]]);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
function up(_x11) {
|
|
|
|
|
return _ref10.apply(this, arguments);
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return up;
|
|
|
|
|
}()
|
2017-07-14 16:41:14 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 模糊搜索项目名称或者组名称
|
|
|
|
|
* @interface /project/search
|
|
|
|
|
* @method GET
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
|
|
|
|
* @param {String} q
|
|
|
|
|
* @return {Object}
|
2017-07-14 17:00:30 +08:00
|
|
|
|
* @example ./api/project/search.json
|
2017-07-14 16:41:14 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
key: 'search',
|
|
|
|
|
value: function () {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
|
2017-07-18 16:46:19 +08:00
|
|
|
|
var q, projectList, groupList, projectRules, groupRules, queryList;
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _regenerator2.default.wrap(function _callee11$(_context11) {
|
2017-07-14 16:41:14 +08:00
|
|
|
|
while (1) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
switch (_context11.prev = _context11.next) {
|
2017-07-14 16:41:14 +08:00
|
|
|
|
case 0:
|
|
|
|
|
q = ctx.request.query.q;
|
|
|
|
|
|
|
|
|
|
if (q) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context11.next = 3;
|
2017-07-14 16:41:14 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
|
2017-07-14 16:41:14 +08:00
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
if (_yapi2.default.commons.validateSearchKeyword(q)) {
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context11.next = 5;
|
2017-07-14 16:41:14 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
|
2017-07-14 16:41:14 +08:00
|
|
|
|
|
|
|
|
|
case 5:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
_context11.next = 7;
|
2017-07-14 16:41:14 +08:00
|
|
|
|
return this.Model.search(q);
|
|
|
|
|
|
|
|
|
|
case 7:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
projectList = _context11.sent;
|
|
|
|
|
_context11.next = 10;
|
2017-07-14 16:41:14 +08:00
|
|
|
|
return this.groupModel.search(q);
|
|
|
|
|
|
|
|
|
|
case 10:
|
2017-08-08 19:18:12 +08:00
|
|
|
|
groupList = _context11.sent;
|
2017-08-15 12:08:59 +08:00
|
|
|
|
projectRules = ['_id', 'name', 'basepath', 'uid', 'env', 'members', { key: 'group_id', alias: 'groupId' }, { key: 'up_time', alias: 'upTime' }, { key: 'add_time', alias: 'addTime' }];
|
2017-07-18 16:46:19 +08:00
|
|
|
|
groupRules = ['_id', 'uid', { key: 'group_name', alias: 'groupName' }, { key: 'group_desc', alias: 'groupDesc' }, { key: 'add_time', alias: 'addTime' }, { key: 'up_time', alias: 'upTime' }];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
projectList = _commons2.default.filterRes(projectList, projectRules);
|
|
|
|
|
groupList = _commons2.default.filterRes(groupList, groupRules);
|
|
|
|
|
|
2017-07-14 16:41:14 +08:00
|
|
|
|
queryList = {
|
2017-07-18 16:46:19 +08:00
|
|
|
|
project: projectList,
|
|
|
|
|
group: groupList
|
2017-07-14 16:41:14 +08:00
|
|
|
|
};
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 0, 'ok'));
|
2017-07-14 16:41:14 +08:00
|
|
|
|
|
2017-07-18 16:46:19 +08:00
|
|
|
|
case 17:
|
2017-07-14 16:41:14 +08:00
|
|
|
|
case 'end':
|
2017-08-08 19:18:12 +08:00
|
|
|
|
return _context11.stop();
|
2017-07-14 16:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-08 19:18:12 +08:00
|
|
|
|
}, _callee11, this);
|
2017-07-14 16:41:14 +08:00
|
|
|
|
}));
|
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
|
function search(_x12) {
|
|
|
|
|
return _ref11.apply(this, arguments);
|
2017-07-14 16:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return search;
|
|
|
|
|
}()
|
2017-08-10 12:14:35 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下载项目的 Mock 数据
|
|
|
|
|
* @interface /project/download
|
|
|
|
|
* @method GET
|
|
|
|
|
* @category project
|
|
|
|
|
* @foldnumber 10
|
2017-08-15 12:08:59 +08:00
|
|
|
|
* @author wenbo.dong
|
2017-08-10 12:14:35 +08:00
|
|
|
|
* @param {String} project_id
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
key: 'download',
|
|
|
|
|
value: function () {
|
|
|
|
|
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(ctx) {
|
|
|
|
|
var project_id, interfaceInst, count, arr, fileName, res;
|
|
|
|
|
return _regenerator2.default.wrap(function _callee12$(_context12) {
|
|
|
|
|
while (1) {
|
|
|
|
|
switch (_context12.prev = _context12.next) {
|
|
|
|
|
case 0:
|
|
|
|
|
project_id = ctx.request.query.project_id;
|
|
|
|
|
interfaceInst = _yapi2.default.getInst(_interface2.default);
|
2017-08-10 21:20:57 +08:00
|
|
|
|
// 根据 project_id 获取接口数据
|
|
|
|
|
|
2017-08-10 12:14:35 +08:00
|
|
|
|
_context12.next = 4;
|
|
|
|
|
return interfaceInst.list(project_id);
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
count = _context12.sent;
|
|
|
|
|
|
2017-08-10 21:20:57 +08:00
|
|
|
|
if (project_id) {
|
|
|
|
|
_context12.next = 9;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
|
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
|
if (count) {
|
|
|
|
|
_context12.next = 11;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '项目id不存在'));
|
|
|
|
|
|
|
|
|
|
case 11:
|
2017-08-10 12:14:35 +08:00
|
|
|
|
arr = (0, _stringify2.default)(count.map(function (item) {
|
|
|
|
|
// 返回的json模板数据: item.res_body
|
|
|
|
|
var mockData = _mockjs2.default.mock(_yapi2.default.commons.json_parse(item.res_body));
|
|
|
|
|
return {
|
|
|
|
|
path: item.path,
|
|
|
|
|
mock: mockData
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
fileName = 'mock.js';
|
|
|
|
|
|
|
|
|
|
ctx.attachment(fileName);
|
2017-08-10 21:20:57 +08:00
|
|
|
|
_context12.next = 16;
|
2017-08-10 12:14:35 +08:00
|
|
|
|
return send(ctx, fileName, { root: __dirname + '/public' });
|
|
|
|
|
|
2017-08-10 21:20:57 +08:00
|
|
|
|
case 16:
|
|
|
|
|
res = ('\n var Mock = require(\'mockjs\');\n var xhook = require(\'xhook\');\n var data = ' + arr + ';\n function run() {\n xhook.before(function(request, callback) {\n setTimeout(function() {\n var res;\n data.forEach((item) => {\n // \u8BF7\u6C42\u7684\u63A5\u53E3\u5728 data \u4E2D\u5B58\u5728\n if(request.url === item.path) {\n res = {\n status: 200,\n text: Mock.mock(item.mock)\n }\n }\n });\n if (res) {\n callback(res);\n }else {\n callback({ status: 405, text: \'\u63A5\u53E3\u4E0D\u5B58\u5728\' });\n }\n }, 500);\n });\n }\n module.exports = run;').trim();
|
2017-08-10 12:14:35 +08:00
|
|
|
|
return _context12.abrupt('return', ctx.body = res);
|
|
|
|
|
|
2017-08-10 21:20:57 +08:00
|
|
|
|
case 18:
|
2017-08-10 12:14:35 +08:00
|
|
|
|
case 'end':
|
|
|
|
|
return _context12.stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, _callee12, this);
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
function download(_x13) {
|
|
|
|
|
return _ref12.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return download;
|
|
|
|
|
}()
|
2017-07-06 19:21:54 +08:00
|
|
|
|
}]);
|
|
|
|
|
return projectController;
|
|
|
|
|
}(_base2.default);
|
|
|
|
|
|
|
|
|
|
module.exports = projectController;
|