yapi/server_dist/controllers/interfaceCol.js
2017-08-09 16:16:35 +08:00

544 lines
19 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
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);
var _interfaceCol = require('../models/interfaceCol.js');
var _interfaceCol2 = _interopRequireDefault(_interfaceCol);
var _interfaceCase = require('../models/interfaceCase.js');
var _interfaceCase2 = _interopRequireDefault(_interfaceCase);
var _base = require('./base.js');
var _base2 = _interopRequireDefault(_base);
var _yapi = require('../yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var interfaceColController = function (_baseController) {
(0, _inherits3.default)(interfaceColController, _baseController);
function interfaceColController(ctx) {
(0, _classCallCheck3.default)(this, interfaceColController);
var _this = (0, _possibleConstructorReturn3.default)(this, (interfaceColController.__proto__ || (0, _getPrototypeOf2.default)(interfaceColController)).call(this, ctx));
_this.colModel = _yapi2.default.getInst(_interfaceCol2.default);
_this.caseModel = _yapi2.default.getInst(_interfaceCase2.default);
return _this;
}
/**
* 获取所有接口集
* @interface /col/list
* @method GET
* @category col
* @foldnumber 10
* @param {String} project_id email名称不能为空
* @returns {Object}
* @example
*/
(0, _createClass3.default)(interfaceColController, [{
key: 'list',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var id, inst, result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
id = ctx.query.project_id;
inst = _yapi2.default.getInst(_interfaceCol2.default);
_context.next = 5;
return inst.list(id);
case 5:
result = _context.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 12;
break;
case 9:
_context.prev = 9;
_context.t0 = _context['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
case 12:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[0, 9]]);
}));
function list(_x) {
return _ref.apply(this, arguments);
}
return list;
}()
/**
* 增加接口集
* @interface /col/add_col
* @method POST
* @category col
* @foldnumber 10
* @param {Number} project_id
* @param {String} name
* @param {String} desc
* @returns {Object}
* @example
*/
}, {
key: 'addCol',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
params = ctx.request.body;
params = _yapi2.default.commons.handleParams(params, {
name: 'string',
project_id: 'number',
desc: 'string'
});
if (params.project_id) {
_context2.next = 5;
break;
}
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 5:
if (params.name) {
_context2.next = 7;
break;
}
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '名称不能为空'));
case 7:
_context2.next = 9;
return this.colModel.save({
name: params.name,
project_id: params.project_id,
desc: params.desc,
uid: this.getUid(),
add_time: _yapi2.default.commons.time(),
up_time: _yapi2.default.commons.time()
});
case 9:
result = _context2.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context2.next = 16;
break;
case 13:
_context2.prev = 13;
_context2.t0 = _context2['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context2.t0.message);
case 16:
case 'end':
return _context2.stop();
}
}
}, _callee2, this, [[0, 13]]);
}));
function addCol(_x2) {
return _ref2.apply(this, arguments);
}
return addCol;
}()
/**
* 获取一个接口集下的所有的接口用例
* @interface /col/case_list
* @method GET
* @category col
* @foldnumber 10
* @param {String} col_id 接口集id
* @returns {Object}
* @example
*/
}, {
key: 'getCaseList',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
var id, inst, result;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
id = ctx.query.col_id;
inst = _yapi2.default.getInst(_interfaceCase2.default);
_context3.next = 5;
return inst.list(id);
case 5:
result = _context3.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context3.next = 12;
break;
case 9:
_context3.prev = 9;
_context3.t0 = _context3['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
case 12:
case 'end':
return _context3.stop();
}
}
}, _callee3, this, [[0, 9]]);
}));
function getCaseList(_x3) {
return _ref3.apply(this, arguments);
}
return getCaseList;
}()
/**
* 增加一个接口用例
* @interface /col/add_case
* @method POST
* @category col
* @foldnumber 10
* @param {String} casename
* @param {Number} col_id
* @param {Number} project_id
* @param {String} env
* @param {String} domain
* @param {String} path
* @param {String} method
* @param {Object} req_query
* @param {Object} req_headers
* @param {String} req_body_type
* @param {Array} req_body_form
* @param {String} req_body_other
* @returns {Object}
* @example
*/
}, {
key: 'addCase',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.prev = 0;
params = ctx.request.body;
params = _yapi2.default.commons.handleParams(params, {
casename: 'string',
project_id: 'number',
col_id: 'number',
env: 'string',
domain: 'string',
method: 'string'
});
if (params.project_id) {
_context4.next = 5;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 5:
if (params.col_id) {
_context4.next = 7;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 7:
if (params.env) {
_context4.next = 9;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '缺少环境配置'));
case 9:
if (params.casename) {
_context4.next = 11;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '用例名称不能为空'));
case 11:
params.uid = this.getUid();
params.index = 0;
params.add_time = _yapi2.default.commons.time();
params.up_time = _yapi2.default.commons.time();
_context4.next = 17;
return this.caseModel.save(params);
case 17:
result = _context4.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 24;
break;
case 21:
_context4.prev = 21;
_context4.t0 = _context4['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
case 24:
case 'end':
return _context4.stop();
}
}
}, _callee4, this, [[0, 21]]);
}));
function addCase(_x4) {
return _ref4.apply(this, arguments);
}
return addCase;
}()
/**
* 获取一个接口用例详情
* @interface /col/case
* @method GET
* @category col
* @foldnumber 10
* @param {String} caseid
* @returns {Object}
* @example
*/
}, {
key: 'getCase',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var id, result;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.prev = 0;
id = ctx.query.caseid;
_context5.next = 4;
return this.caseModel.get(id);
case 4:
result = _context5.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context5.next = 11;
break;
case 8:
_context5.prev = 8;
_context5.t0 = _context5['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context5.t0.message);
case 11:
case 'end':
return _context5.stop();
}
}
}, _callee5, this, [[0, 8]]);
}));
function getCase(_x5) {
return _ref5.apply(this, arguments);
}
return getCase;
}()
/**
* 更新一个接口集name或描述
* @interface /col/up_col
* @method GET
* @category col
* @foldnumber 10
* @param {String} name
* @param {String} desc
* @returns {Object}
* @example
*/
}, {
key: 'upCol',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.prev = 0;
params = ctx.request.body;
_context6.next = 4;
return this.caseModel.up(params.col_id, {
name: params.col_name,
desc: params.col_desc,
up_time: _yapi2.default.commons.time()
});
case 4:
result = _context6.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context6.next = 11;
break;
case 8:
_context6.prev = 8;
_context6.t0 = _context6['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context6.t0.message);
case 11:
case 'end':
return _context6.stop();
}
}
}, _callee6, this, [[0, 8]]);
}));
function upCol(_x6) {
return _ref6.apply(this, arguments);
}
return upCol;
}()
/**
* 删除一个接口集
* @interface /col/del
* @method GET
* @category col
* @foldnumber 10
* @param {String}
* @returns {Object}
* @example
*/
}, {
key: 'delCol',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
case 'end':
return _context7.stop();
}
}
}, _callee7, this);
}));
function delCol(_x7) {
return _ref7.apply(this, arguments);
}
return delCol;
}()
/**
*
* @param {*} ctx
*/
}, {
key: 'delCase',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
case 'end':
return _context8.stop();
}
}
}, _callee8, this);
}));
function delCase(_x8) {
return _ref8.apply(this, arguments);
}
return delCase;
}()
}]);
return interfaceColController;
}(_base2.default);
module.exports = interfaceColController;