mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-30 13:20:24 +08:00
fix: 解决commons冲突
This commit is contained in:
commit
febcec21b1
@ -269,6 +269,9 @@ class projectController extends baseController {
|
||||
}
|
||||
try {
|
||||
let result = await this.Model.get(params.id);
|
||||
result = result.toObject();
|
||||
delete result.members;
|
||||
result.role = await this.getProjectRole(params.id, 'project');
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
@ -332,15 +335,18 @@ class projectController extends baseController {
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
let interfaceInst = yapi.getInst(interfaceModel);
|
||||
let count = await interfaceInst.countByProjectId(id);
|
||||
if (count > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '请先删除该项目下所有接口');
|
||||
}
|
||||
|
||||
|
||||
if (await this.checkAuth(id, 'project', 'danger') !== true) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
|
||||
let interfaceInst = yapi.getInst(interfaceModel);
|
||||
let interfaceColInst = yapi.getInst(interfaceColModel);
|
||||
let interfaceCaseInst = yapi.getInst(interfaceCaseModel);
|
||||
await interfaceInst.delByProjectId(id)
|
||||
await interfaceCaseInst.delByProjectId(id)
|
||||
await interfaceColInst.delByProjectId(id)
|
||||
|
||||
let result = await this.Model.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
|
@ -3,6 +3,7 @@ import path from 'path';
|
||||
import yapi from '../yapi.js';
|
||||
import sha1 from 'sha1';
|
||||
import logModel from '../models/log.js';
|
||||
import json5 from 'json5';
|
||||
|
||||
exports.resReturn = (data, num, errmsg) => {
|
||||
num = num || 0;
|
||||
@ -90,7 +91,7 @@ exports.rand = (min, max) => {
|
||||
|
||||
exports.json_parse = (json) => {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
return json5.parse(json);
|
||||
} catch (e) {
|
||||
return json;
|
||||
}
|
||||
|
@ -628,22 +628,30 @@ var projectController = function (_baseController) {
|
||||
case 6:
|
||||
result = _context6.sent;
|
||||
|
||||
result = result.toObject();
|
||||
delete result.members;
|
||||
_context6.next = 11;
|
||||
return this.getProjectRole(params.id, 'project');
|
||||
|
||||
case 11:
|
||||
result.role = _context6.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context6.next = 13;
|
||||
_context6.next = 18;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
_context6.prev = 10;
|
||||
case 15:
|
||||
_context6.prev = 15;
|
||||
_context6.t0 = _context6['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
||||
|
||||
case 13:
|
||||
case 18:
|
||||
case 'end':
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee6, this, [[3, 10]]);
|
||||
}, _callee6, this, [[3, 15]]);
|
||||
}));
|
||||
|
||||
function get(_x7) {
|
||||
@ -754,7 +762,7 @@ var projectController = function (_baseController) {
|
||||
key: 'del',
|
||||
value: function () {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var _id, interfaceInst, count, result;
|
||||
var _id, interfaceInst, interfaceColInst, interfaceCaseInst, result;
|
||||
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
while (1) {
|
||||
@ -771,57 +779,57 @@ var projectController = function (_baseController) {
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
|
||||
case 4:
|
||||
interfaceInst = _yapi2.default.getInst(_interface2.default);
|
||||
_context8.next = 7;
|
||||
return interfaceInst.countByProjectId(_id);
|
||||
|
||||
case 7:
|
||||
count = _context8.sent;
|
||||
|
||||
if (!(count > 0)) {
|
||||
_context8.next = 10;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
|
||||
|
||||
case 10:
|
||||
_context8.next = 12;
|
||||
_context8.next = 6;
|
||||
return this.checkAuth(_id, 'project', 'danger');
|
||||
|
||||
case 12:
|
||||
case 6:
|
||||
_context8.t0 = _context8.sent;
|
||||
|
||||
if (!(_context8.t0 !== true)) {
|
||||
_context8.next = 15;
|
||||
_context8.next = 9;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 15:
|
||||
_context8.next = 17;
|
||||
case 9:
|
||||
interfaceInst = _yapi2.default.getInst(_interface2.default);
|
||||
interfaceColInst = _yapi2.default.getInst(interfaceColModel);
|
||||
interfaceCaseInst = _yapi2.default.getInst(interfaceCaseModel);
|
||||
_context8.next = 14;
|
||||
return interfaceInst.delByProjectId(_id);
|
||||
|
||||
case 14:
|
||||
_context8.next = 16;
|
||||
return interfaceCaseInst.delByProjectId(_id);
|
||||
|
||||
case 16:
|
||||
_context8.next = 18;
|
||||
return interfaceColInst.delByProjectId(_id);
|
||||
|
||||
case 18:
|
||||
_context8.next = 20;
|
||||
return this.Model.del(_id);
|
||||
|
||||
case 17:
|
||||
case 20:
|
||||
result = _context8.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context8.next = 24;
|
||||
_context8.next = 27;
|
||||
break;
|
||||
|
||||
case 21:
|
||||
_context8.prev = 21;
|
||||
case 24:
|
||||
_context8.prev = 24;
|
||||
_context8.t1 = _context8['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
|
||||
|
||||
case 24:
|
||||
case 27:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this, [[0, 21]]);
|
||||
}, _callee8, this, [[0, 24]]);
|
||||
}));
|
||||
|
||||
function del(_x9) {
|
||||
|
@ -28,6 +28,10 @@ var _log = require('../models/log.js');
|
||||
|
||||
var _log2 = _interopRequireDefault(_log);
|
||||
|
||||
var _json = require('json5');
|
||||
|
||||
var _json2 = _interopRequireDefault(_json);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
exports.resReturn = function (data, num, errmsg) {
|
||||
@ -115,7 +119,7 @@ exports.rand = function (min, max) {
|
||||
|
||||
exports.json_parse = function (json) {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
return _json2.default.parse(json);
|
||||
} catch (e) {
|
||||
return json;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user