mirror of
https://github.com/YMFE/yapi.git
synced 2025-02-17 13:49:43 +08:00
feat: 前端添加avatar
This commit is contained in:
parent
58e4885aff
commit
d2d1ebf4b3
@ -23,7 +23,7 @@ class interfaceColController extends baseController{
|
||||
async list(ctx){
|
||||
try {
|
||||
let id = ctx.query.project_id;
|
||||
let inst = yapi.getInst(interfaceColModel);
|
||||
let inst = this.colModel(interfaceColModel);
|
||||
let result = await inst.list(id);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
@ -59,6 +59,7 @@ class interfaceColController extends baseController{
|
||||
if(!params.name){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '名称不能为空');
|
||||
}
|
||||
|
||||
let result = await this.colModel.save({
|
||||
name: params.name,
|
||||
project_id: params.project_id,
|
||||
@ -139,6 +140,10 @@ class interfaceColController extends baseController{
|
||||
if (!params.env) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '缺少环境配置');
|
||||
}
|
||||
if (!params.path) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, 'path 不能为空');
|
||||
}
|
||||
|
||||
|
||||
if(!params.casename){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '用例名称不能为空');
|
||||
@ -181,7 +186,7 @@ class interfaceColController extends baseController{
|
||||
/**
|
||||
* 更新一个接口集name或描述
|
||||
* @interface /col/up_col
|
||||
* @method GET
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {String} name
|
||||
@ -204,9 +209,41 @@ class interfaceColController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新多个接口case index
|
||||
* @interface /col/up_col_index
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {Array} [id, index]
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async upCaseIndex(ctx){
|
||||
try{
|
||||
let params = ctx.request.body;
|
||||
if(!params || !Array.isArray(params)){
|
||||
ctx.body = yapi.commons.resReturn(null, 400, "请求参数必须是数组")
|
||||
}
|
||||
params.forEach((item) => {
|
||||
if(item.id && item.index){
|
||||
this.caseModel.upCaseIndex(item.id, item.index).then((res) => {}, (err) => {
|
||||
yapi.commons.log(err.message, 'error')
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return ctx.body = yapi.commons.resReturn('success')
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 400, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个接口集
|
||||
* @interface /col/del
|
||||
* @interface /col/del_col
|
||||
* @method GET
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
@ -216,7 +253,27 @@ class interfaceColController extends baseController{
|
||||
*/
|
||||
|
||||
async delCol(ctx){
|
||||
try{
|
||||
let id = ctx.request.body.colid;
|
||||
let colData = await this.colModel.get(id);
|
||||
if(!colData){
|
||||
ctx.body = yapi.commons.resReturn(null, 400, "不存在的id")
|
||||
}
|
||||
|
||||
if(colData.uid !== this.getUid()){
|
||||
let auth = await this.checkAuth(colData.project_id, 'project', 'danger')
|
||||
if(!auth){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
let result = await this.colModel.del(caseid);
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
|
||||
}catch(e){
|
||||
yapi.commons.resReturn(null, 400, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,7 +282,27 @@ class interfaceColController extends baseController{
|
||||
*/
|
||||
|
||||
async delCase(ctx){
|
||||
try{
|
||||
let caseid = ctx.request.body.caseid;
|
||||
let caseData = await this.caseModel.get(caseid);
|
||||
if(!caseData){
|
||||
ctx.body = yapi.commons.resReturn(null, 400, "不存在的caseid")
|
||||
}
|
||||
|
||||
if(caseData.uid !== this.getUid()){
|
||||
let auth = await this.checkAuth(caseData.project_id, 'project', 'danger')
|
||||
if(!auth){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
let result = await this.caseModel.del(caseid);
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
|
||||
}catch(e){
|
||||
yapi.commons.resReturn(null, 400, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@ import baseModel from './base.js';
|
||||
|
||||
class interfaceCase extends baseModel {
|
||||
getName() {
|
||||
return 'interface_col';
|
||||
return 'interface_case';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
@ -16,7 +16,7 @@ class interfaceCase extends baseModel {
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
env: { type: String, required: true },
|
||||
domain: {type: String, required:true },
|
||||
domain: {type: String },
|
||||
path: { type: String, required: true },
|
||||
method: { type: String, required: true },
|
||||
req_query: [{
|
||||
@ -65,6 +65,14 @@ class interfaceCase extends baseModel {
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
upCaseIndex(id, index){
|
||||
return this.model.update({
|
||||
_id: id
|
||||
},{
|
||||
index: index
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = interfaceCase;
|
@ -227,14 +227,43 @@ const routerConfig = {
|
||||
}
|
||||
],
|
||||
"col": [{
|
||||
action: "add",
|
||||
path: "add",
|
||||
action: "addCol",
|
||||
path: "add_col",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "list",
|
||||
path: "list",
|
||||
method: "get"
|
||||
}]
|
||||
},{
|
||||
action: "getCaseList",
|
||||
path: "case_list",
|
||||
method: "get"
|
||||
},{
|
||||
action: "addCase",
|
||||
path: "add_case",
|
||||
method: "post"
|
||||
},{
|
||||
action: "getCase",
|
||||
path: "case",
|
||||
method: "get"
|
||||
},{
|
||||
action: "upCol",
|
||||
path: "up_col",
|
||||
method: "post"
|
||||
},{
|
||||
action: "upCaseIndex",
|
||||
path: "up_col_index",
|
||||
method: "post"
|
||||
},{
|
||||
action: "delCol",
|
||||
path: "del_col",
|
||||
method: "post"
|
||||
},{
|
||||
action: "delCase",
|
||||
path: "del_case",
|
||||
method: "post"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
for(let ctrl in routerConfig){
|
||||
@ -260,7 +289,7 @@ function createAction(controller, action, path, method) {
|
||||
if (inst.$auth === true) {
|
||||
await inst[action].call(inst, ctx);
|
||||
} else {
|
||||
ctx.body = yapi.commons.resReturn(null, 400, 'Without Permission.');
|
||||
ctx.body = yapi.commons.resReturn(null, 40011, '请登录.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ var interfaceColController = function (_baseController) {
|
||||
case 0:
|
||||
_context.prev = 0;
|
||||
id = ctx.query.project_id;
|
||||
inst = _yapi2.default.getInst(_interfaceCol2.default);
|
||||
inst = this.colModel(_interfaceCol2.default);
|
||||
_context.next = 5;
|
||||
return inst.list(id);
|
||||
|
||||
@ -321,43 +321,51 @@ var interfaceColController = function (_baseController) {
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '缺少环境配置'));
|
||||
|
||||
case 9:
|
||||
if (params.casename) {
|
||||
if (params.path) {
|
||||
_context4.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'path 不能为空'));
|
||||
|
||||
case 11:
|
||||
if (params.casename) {
|
||||
_context4.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '用例名称不能为空'));
|
||||
|
||||
case 11:
|
||||
case 13:
|
||||
|
||||
params.uid = this.getUid();
|
||||
params.index = 0;
|
||||
params.add_time = _yapi2.default.commons.time();
|
||||
params.up_time = _yapi2.default.commons.time();
|
||||
_context4.next = 17;
|
||||
_context4.next = 19;
|
||||
return this.caseModel.save(params);
|
||||
|
||||
case 17:
|
||||
case 19:
|
||||
result = _context4.sent;
|
||||
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
|
||||
_context4.next = 24;
|
||||
_context4.next = 26;
|
||||
break;
|
||||
|
||||
case 21:
|
||||
_context4.prev = 21;
|
||||
case 23:
|
||||
_context4.prev = 23;
|
||||
_context4.t0 = _context4['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
|
||||
case 24:
|
||||
case 26:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[0, 21]]);
|
||||
}, _callee4, this, [[0, 23]]);
|
||||
}));
|
||||
|
||||
function addCase(_x4) {
|
||||
@ -423,7 +431,7 @@ var interfaceColController = function (_baseController) {
|
||||
/**
|
||||
* 更新一个接口集name或描述
|
||||
* @interface /col/up_col
|
||||
* @method GET
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {String} name
|
||||
@ -478,9 +486,68 @@ var interfaceColController = function (_baseController) {
|
||||
return upCol;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 更新多个接口case index
|
||||
* @interface /col/up_col_index
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {Array} [id, index]
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'upCaseIndex',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var _this2 = this;
|
||||
|
||||
var params;
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
case 0:
|
||||
_context7.prev = 0;
|
||||
params = ctx.request.body;
|
||||
|
||||
if (!params || !Array.isArray(params)) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "请求参数必须是数组");
|
||||
}
|
||||
params.forEach(function (item) {
|
||||
if (item.id && item.index) {
|
||||
_this2.caseModel.upCaseIndex(item.id, item.index).then(function (res) {}, function (err) {
|
||||
_yapi2.default.commons.log(err.message, 'error');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn('success'));
|
||||
|
||||
case 7:
|
||||
_context7.prev = 7;
|
||||
_context7.t0 = _context7['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context7.t0.message);
|
||||
|
||||
case 10:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this, [[0, 7]]);
|
||||
}));
|
||||
|
||||
function upCaseIndex(_x7) {
|
||||
return _ref7.apply(this, arguments);
|
||||
}
|
||||
|
||||
return upCaseIndex;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 删除一个接口集
|
||||
* @interface /col/del
|
||||
* @interface /col/del_col
|
||||
* @method GET
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
@ -492,20 +559,66 @@ var interfaceColController = function (_baseController) {
|
||||
}, {
|
||||
key: 'delCol',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var id, colData, auth, result;
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
case 0:
|
||||
_context8.prev = 0;
|
||||
id = ctx.request.body.colid;
|
||||
_context8.next = 4;
|
||||
return this.colModel.get(id);
|
||||
|
||||
case 4:
|
||||
colData = _context8.sent;
|
||||
|
||||
if (!colData) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的id");
|
||||
}
|
||||
|
||||
if (!(colData.uid !== this.getUid())) {
|
||||
_context8.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 9;
|
||||
return this.checkAuth(colData.project_id, 'project', 'danger');
|
||||
|
||||
case 9:
|
||||
auth = _context8.sent;
|
||||
|
||||
if (auth) {
|
||||
_context8.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context8.next = 14;
|
||||
return this.colModel.del(caseid);
|
||||
|
||||
case 14:
|
||||
result = _context8.sent;
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 18:
|
||||
_context8.prev = 18;
|
||||
_context8.t0 = _context8['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context8.t0.message);
|
||||
|
||||
case 21:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this);
|
||||
}, _callee8, this, [[0, 18]]);
|
||||
}));
|
||||
|
||||
function delCol(_x7) {
|
||||
return _ref7.apply(this, arguments);
|
||||
function delCol(_x8) {
|
||||
return _ref8.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delCol;
|
||||
@ -519,20 +632,67 @@ var interfaceColController = function (_baseController) {
|
||||
}, {
|
||||
key: 'delCase',
|
||||
value: function () {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var _caseid, caseData, auth, result;
|
||||
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
case 0:
|
||||
_context9.prev = 0;
|
||||
_caseid = ctx.request.body.caseid;
|
||||
_context9.next = 4;
|
||||
return this.caseModel.get(_caseid);
|
||||
|
||||
case 4:
|
||||
caseData = _context9.sent;
|
||||
|
||||
if (!caseData) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的caseid");
|
||||
}
|
||||
|
||||
if (!(caseData.uid !== this.getUid())) {
|
||||
_context9.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
_context9.next = 9;
|
||||
return this.checkAuth(caseData.project_id, 'project', 'danger');
|
||||
|
||||
case 9:
|
||||
auth = _context9.sent;
|
||||
|
||||
if (auth) {
|
||||
_context9.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context9.next = 14;
|
||||
return this.caseModel.del(_caseid);
|
||||
|
||||
case 14:
|
||||
result = _context9.sent;
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 18:
|
||||
_context9.prev = 18;
|
||||
_context9.t0 = _context9['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context9.t0.message);
|
||||
|
||||
case 21:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
return _context9.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this);
|
||||
}, _callee9, this, [[0, 18]]);
|
||||
}));
|
||||
|
||||
function delCase(_x8) {
|
||||
return _ref8.apply(this, arguments);
|
||||
function delCase(_x9) {
|
||||
return _ref9.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delCase;
|
||||
|
@ -41,7 +41,7 @@ var interfaceCase = function (_baseModel) {
|
||||
(0, _createClass3.default)(interfaceCase, [{
|
||||
key: 'getName',
|
||||
value: function getName() {
|
||||
return 'interface_col';
|
||||
return 'interface_case';
|
||||
}
|
||||
}, {
|
||||
key: 'getSchema',
|
||||
@ -55,7 +55,7 @@ var interfaceCase = function (_baseModel) {
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
env: { type: String, required: true },
|
||||
domain: { type: String, required: true },
|
||||
domain: { type: String },
|
||||
path: { type: String, required: true },
|
||||
method: { type: String, required: true },
|
||||
req_query: [{
|
||||
@ -106,6 +106,15 @@ var interfaceCase = function (_baseModel) {
|
||||
data.up_time = _yapi2.default.commons.time();
|
||||
return this.model.update({ _id: id }, data);
|
||||
}
|
||||
}, {
|
||||
key: 'upCaseIndex',
|
||||
value: function upCaseIndex(id, index) {
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, {
|
||||
index: index
|
||||
});
|
||||
}
|
||||
}]);
|
||||
return interfaceCase;
|
||||
}(_base2.default);
|
||||
|
@ -222,13 +222,41 @@ var routerConfig = {
|
||||
"method": "get"
|
||||
}],
|
||||
"col": [{
|
||||
action: "add",
|
||||
path: "add",
|
||||
action: "addCol",
|
||||
path: "add_col",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "list",
|
||||
path: "list",
|
||||
method: "get"
|
||||
}, {
|
||||
action: "getCaseList",
|
||||
path: "case_list",
|
||||
method: "get"
|
||||
}, {
|
||||
action: "addCase",
|
||||
path: "add_case",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "getCase",
|
||||
path: "case",
|
||||
method: "get"
|
||||
}, {
|
||||
action: "upCol",
|
||||
path: "up_col",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "upCaseIndex",
|
||||
path: "up_col_index",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "delCol",
|
||||
path: "del_col",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "delCase",
|
||||
path: "del_case",
|
||||
method: "post"
|
||||
}]
|
||||
};
|
||||
|
||||
@ -278,7 +306,7 @@ function createAction(controller, action, path, method) {
|
||||
break;
|
||||
|
||||
case 8:
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, 'Without Permission.');
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 40011, '请登录.');
|
||||
|
||||
case 9:
|
||||
case 'end':
|
||||
|
Loading…
Reference in New Issue
Block a user