diff --git a/client/containers/Group/GroupList/GroupList.js b/client/containers/Group/GroupList/GroupList.js index ab38626e..548ec699 100644 --- a/client/containers/Group/GroupList/GroupList.js +++ b/client/containers/Group/GroupList/GroupList.js @@ -167,11 +167,13 @@ export default class GroupList extends Component { showConfirm =()=> { let that = this; confirm({ - title: "确认删除"+that.props.currGroup.group_name+"分组吗?", + title: "确认删除 "+that.props.currGroup.group_name+" 分组吗?", content:
请输入分组名称确认此操作:
+ +请输入项目名称确认此操作:
+ +项目一旦删除,将无法恢复数据,请慎重操作!
- + diff --git a/client/reducer/modules/interface.js b/client/reducer/modules/interface.js index 95a67c55..08d6e4ea 100644 --- a/client/reducer/modules/interface.js +++ b/client/reducer/modules/interface.js @@ -91,7 +91,7 @@ export async function fetchInterfaceData(interfaceId) { } export async function fetchInterfaceList(projectId) { - let result = await axios.get('/api/interface/list?project_id=' + projectId); + let result = await axios.get('/api/interface/list_menu?project_id=' + projectId); return { type: FETCH_INTERFACE_LIST, payload: result.data diff --git a/server/app.js b/server/app.js index 28219a9a..69507133 100644 --- a/server/app.js +++ b/server/app.js @@ -24,7 +24,7 @@ app.use(router.allowedMethods()); websocket(app); app.use( async (ctx, next) => { - if( /^\/(?!api)[a-zA-Z0-9\/\-]*$/.test(ctx.path) ){ + if( /^\/(?!api)[a-zA-Z0-9\/\-_]*$/.test(ctx.path) ){ ctx.path = "/" await next() }else{ diff --git a/server/controllers/interface.js b/server/controllers/interface.js index 3700d38c..b1973701 100644 --- a/server/controllers/interface.js +++ b/server/controllers/interface.js @@ -1,4 +1,5 @@ import interfaceModel from '../models/interface.js'; +import interfaceCatModel from '../models/interfaceCat.js'; import baseController from './base.js'; import yapi from '../yapi.js'; import userModel from '../models/user.js'; @@ -7,6 +8,7 @@ class interfaceController extends baseController { constructor(ctx) { super(ctx); this.Model = yapi.getInst(interfaceModel); + this.catModel = yapi.getInst(interfaceCatModel) } /** @@ -45,7 +47,8 @@ class interfaceController extends baseController { title: 'string', path: 'string', method: 'string', - desc: 'string' + desc: 'string', + catid: 'number' }); params.method = params.method || 'GET'; params.method = params.method.toUpperCase(); @@ -72,6 +75,7 @@ class interfaceController extends baseController { try { let data = { project_id: params.project_id, + catid: params.catid, title: params.title, path: params.path, desc: params.desc, @@ -159,6 +163,43 @@ class interfaceController extends baseController { } } + async listByCat(ctx) { + let catid = ctx.request.query.catid; + if (!catid) { + return ctx.body = yapi.commons.resReturn(null, 400, 'catid不能为空'); + } + try { + let result = await this.Model.listByCatid(catid) + ctx.body = yapi.commons.resReturn(result); + } catch (err) { + ctx.body = yapi.commons.resReturn(null, 402, err.message); + } + + } + + async listByMenu(ctx) { + let project_id = ctx.request.query.project_id; + if (!project_id) { + return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'); + } + try { + let result = await this.catModel.list(project_id), newResult = []; + for(let i=0, item, list;i< result.length; i++){ + item = result[i].toObject() + list = await this.Model.listByCatid(item._id, '_id title method') + for(let j=0; j< list.length; j++){ + list[j] = list[j].toObject() + } + item.list = list; + newResult[i] = item + } + ctx.body = yapi.commons.resReturn(newResult); + } catch (err) { + ctx.body = yapi.commons.resReturn(null, 402, err.message); + } + + } + /** * 编辑接口 * @interface /interface/up @@ -193,7 +234,8 @@ class interfaceController extends baseController { title: 'string', path: 'string', method: 'string', - desc: 'string' + desc: 'string', + catid: 'number' }); params.method = params.method || 'GET'; params.method = params.method.toUpperCase(); @@ -233,6 +275,10 @@ class interfaceController extends baseController { data.method = params.method; } + if(params.catid){ + data.catid = params.catid; + } + if (params.req_headers) { data.req_headers = params.req_headers; } @@ -313,29 +359,101 @@ class interfaceController extends baseController { try { let id = parseInt(ctx.query.id, 10), result, userInst, userinfo, data; if (!id) return ctx.websocket.send("id 参数有误"); - result = await this.Model.get(id), userinfo; - if(result.edit_uid !== 0 && result.edit_uid !== this.getUid()){ + result = await this.Model.get(id), userinfo; + if (result.edit_uid !== 0 && result.edit_uid !== this.getUid()) { userInst = yapi.getInst(userModel); userinfo = await userInst.findById(result.edit_uid); data = { errno: result.edit_uid, - data: {uid: result.edit_uid, username: userinfo.username} + data: { uid: result.edit_uid, username: userinfo.username } } - }else{ - this.Model.upEditUid(id, this.getUid() ).then() + } else { + this.Model.upEditUid(id, this.getUid()).then() data = { errno: 0, data: result } } - ctx.websocket.send(JSON.stringify(data)); - ctx.websocket.on('close', ()=> { + ctx.websocket.send(JSON.stringify(data)); + ctx.websocket.on('close', () => { this.Model.upEditUid(id, 0).then() }) } catch (err) { yapi.commons.log(err, 'error') } } + + async addCat(ctx) { + try { + let params = ctx.request.body; + params = yapi.commons.handleParams(params, { + name: 'string', + project_id: 'number', + desc: 'string' + }); + + if (!params.project_id) { + return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'); + } + if (!params.name) { + return ctx.body = yapi.commons.resReturn(null, 400, '名称不能为空'); + } + + let result = await this.catModel.save({ + name: params.name, + project_id: params.project_id, + desc: params.desc, + uid: this.getUid(), + add_time: yapi.commons.time(), + up_time: yapi.commons.time() + }) + ctx.body = yapi.commons.resReturn(result); + + } catch (e) { + ctx.body = yapi.commons.resReturn(null, 402, e.message); + } + } + + async upCat(ctx) { + try { + let params = ctx.request.body; + let result = await this.catModel.up(params.catid, { + name: params.cat_name, + desc: params.cat_desc, + up_time: yapi.commons.time() + }) + ctx.body = yapi.commons.resReturn(result) + } catch (e) { + ctx.body = yapi.commons.resReturn(null, 400, e.message) + } + } + + async delCat(ctx) { + try { + let id = ctx.request.body.catid; + let catData = await this.catModel.get(id); + if (!catData) { + ctx.body = yapi.commons.resReturn(null, 400, "不存在的分类") + } + + if (catData.uid !== this.getUid()) { + let auth = await this.checkAuth(catData.project_id, 'project', 'danger') + if (!auth) { + return ctx.body = yapi.commons.resReturn(null, 400, '没有权限'); + } + } + + let result = await this.catModel.del(id); + await this.Model.delByCatid(id) + return ctx.body = yapi.commons.resReturn(result); + + + } catch (e) { + yapi.commons.resReturn(null, 400, e.message) + } + } + + } module.exports = interfaceController; \ No newline at end of file diff --git a/server/controllers/interfaceCol.js b/server/controllers/interfaceCol.js index 79343473..704ad585 100644 --- a/server/controllers/interfaceCol.js +++ b/server/controllers/interfaceCol.js @@ -266,6 +266,7 @@ class interfaceColController extends baseController{ } let result = await this.colModel.del(caseid); + await this.caseModel.delByCol(id) return ctx.body = yapi.commons.resReturn(result); diff --git a/server/controllers/project.js b/server/controllers/project.js index ffb7ef5d..37b4ca74 100644 --- a/server/controllers/project.js +++ b/server/controllers/project.js @@ -288,6 +288,7 @@ class projectController extends baseController { } try { let result = await this.Model.get(params.id); + console.log(result) result = result.toObject(); delete result.members; result.role = await this.getProjectRole(params.id, 'project'); diff --git a/server/models/interface.js b/server/models/interface.js index 3e1574cb..b286f1dd 100644 --- a/server/models/interface.js +++ b/server/models/interface.js @@ -13,6 +13,7 @@ class interfaceModel extends baseModel { path: { type: String, required: true }, method: { type: String, required: true }, project_id: { type: Number, required: true }, + catid: {type: Number, required: true}, edit_uid: {type: Number, default: 0}, status: {type: String, enum: ['undone', 'done'], default: 'undone'}, desc: String, @@ -99,20 +100,35 @@ class interfaceModel extends baseModel { }); } - list(project_id) { + list(project_id, select) { + select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time' return this.model.find({ project_id: project_id }) + .select(select) .sort({ _id: -1 }) .exec(); } + listByCatid(catid, select){ + select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time' + return this.model.find({ + catid: catid + }).select(select).exec(); + } + del(id) { return this.model.deleteOne({ _id: id }); } + delByCatid(id){ + return this.model.deleteMany({ + catid: id + }) + } + delByProjectId(id){ return this.model.deleteMany({ project_id: id diff --git a/server/models/interfaceCase.js b/server/models/interfaceCase.js index 0e3f1047..e1073328 100644 --- a/server/models/interfaceCase.js +++ b/server/models/interfaceCase.js @@ -69,6 +69,12 @@ class interfaceCase extends baseModel { }) } + delByCol(id){ + return this.model.deleteMany({ + col_id: id + }) + } + up(id, data) { data.up_time = yapi.commons.time() return this.model.update( diff --git a/server/models/interfaceCat.js b/server/models/interfaceCat.js new file mode 100644 index 00000000..49879a7f --- /dev/null +++ b/server/models/interfaceCat.js @@ -0,0 +1,69 @@ +import yapi from '../yapi.js'; +import baseModel from './base.js'; + +/** + * 接口分类 + */ +class interfaceCat extends baseModel { + getName() { + return 'interface_cat'; + } + + getSchema() { + return { + name: { type: String, required: true }, + uid: { type: Number, required: true }, + project_id: { type: Number, required: true }, + desc: String, + add_time: Number, + up_time: Number + }; + } + + save(data) { + let m = new this.model(data); + return m.save(); + } + + get(id) { + return this.model.findOne({ + _id: id + }).exec(); + } + + checkRepeat(name) { + return this.model.count({ + name: name + }); + } + + list(project_id) { + return this.model.find({ + project_id: project_id + }).exec(); + } + + del(id) { + return this.model.deleteOne({ + _id: id + }); + } + + delByProjectId(id){ + return this.model.deleteMany({ + project_id: id + }) + } + + up(id, data) { + data.up_time = yapi.commons.time() + return this.model.update( + { + _id: id + }, + data + ); + } +} + +module.exports = interfaceCat; \ No newline at end of file diff --git a/server/router.js b/server/router.js index 42820d60..4a0ee336 100644 --- a/server/router.js +++ b/server/router.js @@ -249,6 +249,27 @@ const routerConfig = { "action": "del", "path": "del", "method": "post" + }, + { + action: 'listByCat', + path: 'list_cat', + method: 'get' + },{ + action: 'listByMenu', + path: 'list_menu', + method: 'get' + },{ + action: 'addCat', + path: 'add_cat', + method: 'post' + },{ + action: 'upCat', + path: 'up_cat', + method: 'post' + },{ + action: 'delCat', + path: 'del_cat', + method: 'post' } ], "log": [ diff --git a/server_dist/app.js b/server_dist/app.js index 4a1d40eb..8de77454 100644 --- a/server_dist/app.js +++ b/server_dist/app.js @@ -70,7 +70,7 @@ app.use(function () { while (1) { switch (_context.prev = _context.next) { case 0: - if (!/^\/(?!api)[a-zA-Z0-9\/\-]*$/.test(ctx.path)) { + if (!/^\/(?!api)[a-zA-Z0-9\/\-_]*$/.test(ctx.path)) { _context.next = 6; break; } diff --git a/server_dist/controllers/interface.js b/server_dist/controllers/interface.js index 45213d7d..9ff4bd94 100644 --- a/server_dist/controllers/interface.js +++ b/server_dist/controllers/interface.js @@ -36,6 +36,10 @@ var _interface = require('../models/interface.js'); var _interface2 = _interopRequireDefault(_interface); +var _interfaceCat = require('../models/interfaceCat.js'); + +var _interfaceCat2 = _interopRequireDefault(_interfaceCat); + var _base = require('./base.js'); var _base2 = _interopRequireDefault(_base); @@ -59,6 +63,7 @@ var interfaceController = function (_baseController) { var _this = (0, _possibleConstructorReturn3.default)(this, (interfaceController.__proto__ || (0, _getPrototypeOf2.default)(interfaceController)).call(this, ctx)); _this.Model = _yapi2.default.getInst(_interface2.default); + _this.catModel = _yapi2.default.getInst(_interfaceCat2.default); return _this; } @@ -109,7 +114,8 @@ var interfaceController = function (_baseController) { title: 'string', path: 'string', method: 'string', - desc: 'string' + desc: 'string', + catid: 'number' }); params.method = params.method || 'GET'; params.method = params.method.toUpperCase(); @@ -156,6 +162,7 @@ var interfaceController = function (_baseController) { _context.prev = 16; data = { project_id: params.project_id, + catid: params.catid, title: params.title, path: params.path, desc: params.desc, @@ -341,6 +348,133 @@ var interfaceController = function (_baseController) { return list; }() + }, { + key: 'listByCat', + value: function () { + var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) { + var catid, result; + return _regenerator2.default.wrap(function _callee4$(_context4) { + while (1) { + switch (_context4.prev = _context4.next) { + case 0: + catid = ctx.request.query.catid; + + if (catid) { + _context4.next = 3; + break; + } + + return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'catid不能为空')); + + case 3: + _context4.prev = 3; + _context4.next = 6; + return this.Model.listByCatid(catid); + + case 6: + result = _context4.sent; + + ctx.body = _yapi2.default.commons.resReturn(result); + _context4.next = 13; + break; + + case 10: + _context4.prev = 10; + _context4.t0 = _context4['catch'](3); + + ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message); + + case 13: + case 'end': + return _context4.stop(); + } + } + }, _callee4, this, [[3, 10]]); + })); + + function listByCat(_x4) { + return _ref4.apply(this, arguments); + } + + return listByCat; + }() + }, { + key: 'listByMenu', + value: function () { + var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) { + var project_id, result, newResult, i, item, list, j; + return _regenerator2.default.wrap(function _callee5$(_context5) { + while (1) { + switch (_context5.prev = _context5.next) { + case 0: + project_id = ctx.request.query.project_id; + + if (project_id) { + _context5.next = 3; + break; + } + + return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空')); + + case 3: + _context5.prev = 3; + _context5.next = 6; + return this.catModel.list(project_id); + + case 6: + result = _context5.sent; + newResult = []; + i = 0; + + case 9: + if (!(i < result.length)) { + _context5.next = 20; + break; + } + + item = result[i].toObject(); + _context5.next = 13; + return this.Model.listByCatid(item._id, '_id title method'); + + case 13: + list = _context5.sent; + + for (j = 0; j < list.length; j++) { + list[j] = list[j].toObject(); + } + item.list = list; + newResult[i] = item; + + case 17: + i++; + _context5.next = 9; + break; + + case 20: + ctx.body = _yapi2.default.commons.resReturn(newResult); + _context5.next = 26; + break; + + case 23: + _context5.prev = 23; + _context5.t0 = _context5['catch'](3); + + ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message); + + case 26: + case 'end': + return _context5.stop(); + } + } + }, _callee5, this, [[3, 23]]); + })); + + function listByMenu(_x5) { + return _ref5.apply(this, arguments); + } + + return listByMenu; + }() /** * 编辑接口 @@ -372,11 +506,11 @@ var interfaceController = function (_baseController) { }, { key: 'up', value: function () { - var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) { + var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) { var params, id, interfaceData, checkRepeat, data, result; - return _regenerator2.default.wrap(function _callee4$(_context4) { + return _regenerator2.default.wrap(function _callee6$(_context6) { while (1) { - switch (_context4.prev = _context4.next) { + switch (_context6.prev = _context6.next) { case 0: params = ctx.request.body; @@ -385,7 +519,8 @@ var interfaceController = function (_baseController) { title: 'string', path: 'string', method: 'string', - desc: 'string' + desc: 'string', + catid: 'number' }); params.method = params.method || 'GET'; params.method = params.method.toUpperCase(); @@ -393,44 +528,44 @@ var interfaceController = function (_baseController) { id = ctx.request.body.id; if (id) { - _context4.next = 7; + _context6.next = 7; break; } - return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空')); + return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空')); case 7: - _context4.next = 9; + _context6.next = 9; return this.Model.get(id); case 9: - interfaceData = _context4.sent; + interfaceData = _context6.sent; if (!(params.path && !_yapi2.default.commons.verifyPath(params.path))) { - _context4.next = 12; + _context6.next = 12; break; } - return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/')); + return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/')); case 12: if (!(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method)) { - _context4.next = 18; + _context6.next = 18; break; } - _context4.next = 15; + _context6.next = 15; return this.Model.checkRepeat(interfaceData.project_id, params.path, params.method); case 15: - checkRepeat = _context4.sent; + checkRepeat = _context6.sent; if (!(checkRepeat > 0)) { - _context4.next = 18; + _context6.next = 18; break; } - return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']')); + return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']')); case 18: data = { @@ -451,6 +586,10 @@ var interfaceController = function (_baseController) { data.method = params.method; } + if (params.catid) { + data.catid = params.catid; + } + if (params.req_headers) { data.req_headers = params.req_headers; } @@ -483,33 +622,33 @@ var interfaceController = function (_baseController) { data.res_body = params.res_body; } - _context4.prev = 31; - _context4.next = 34; + _context6.prev = 32; + _context6.next = 35; return this.Model.up(id, data); - case 34: - result = _context4.sent; + case 35: + result = _context6.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context4.next = 41; + _context6.next = 42; break; - case 38: - _context4.prev = 38; - _context4.t0 = _context4['catch'](31); + case 39: + _context6.prev = 39; + _context6.t0 = _context6['catch'](32); - ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message); + ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message); - case 41: + case 42: case 'end': - return _context4.stop(); + return _context6.stop(); } } - }, _callee4, this, [[31, 38]]); + }, _callee6, this, [[32, 39]]); })); - function up(_x4) { - return _ref4.apply(this, arguments); + function up(_x6) { + return _ref6.apply(this, arguments); } return up; @@ -529,74 +668,74 @@ var interfaceController = function (_baseController) { }, { key: 'del', value: function () { - var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) { + var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) { var id, data, result; - return _regenerator2.default.wrap(function _callee5$(_context5) { + return _regenerator2.default.wrap(function _callee7$(_context7) { while (1) { - switch (_context5.prev = _context5.next) { + switch (_context7.prev = _context7.next) { case 0: - _context5.prev = 0; + _context7.prev = 0; id = ctx.request.body.id; if (id) { - _context5.next = 4; + _context7.next = 4; break; } - return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空')); + return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空')); case 4: - _context5.next = 6; + _context7.next = 6; return this.Model.get(ctx.request.body.id); case 6: - data = _context5.sent; + data = _context7.sent; if (!(data.uid != this.getUid())) { - _context5.next = 13; + _context7.next = 13; break; } - _context5.next = 10; + _context7.next = 10; return this.jungeProjectAuth(data.project_id); case 10: - _context5.t0 = _context5.sent; + _context7.t0 = _context7.sent; - if (!(_context5.t0 !== true)) { - _context5.next = 13; + if (!(_context7.t0 !== true)) { + _context7.next = 13; break; } - return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限')); + return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限')); case 13: - _context5.next = 15; + _context7.next = 15; return this.Model.del(id); case 15: - result = _context5.sent; + result = _context7.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context5.next = 22; + _context7.next = 22; break; case 19: - _context5.prev = 19; - _context5.t1 = _context5['catch'](0); + _context7.prev = 19; + _context7.t1 = _context7['catch'](0); - ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t1.message); + ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t1.message); case 22: case 'end': - return _context5.stop(); + return _context7.stop(); } } - }, _callee5, this, [[0, 19]]); + }, _callee7, this, [[0, 19]]); })); - function del(_x5) { - return _ref5.apply(this, arguments); + function del(_x7) { + return _ref7.apply(this, arguments); } return del; @@ -604,49 +743,49 @@ var interfaceController = function (_baseController) { }, { key: 'solveConflict', value: function () { - var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) { + var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) { var _this2 = this; var id, result, userInst, userinfo, data; - return _regenerator2.default.wrap(function _callee6$(_context6) { + return _regenerator2.default.wrap(function _callee8$(_context8) { while (1) { - switch (_context6.prev = _context6.next) { + switch (_context8.prev = _context8.next) { case 0: - _context6.prev = 0; + _context8.prev = 0; id = parseInt(ctx.query.id, 10), result = void 0, userInst = void 0, userinfo = void 0, data = void 0; if (id) { - _context6.next = 4; + _context8.next = 4; break; } - return _context6.abrupt('return', ctx.websocket.send("id 参数有误")); + return _context8.abrupt('return', ctx.websocket.send("id 参数有误")); case 4: - _context6.next = 6; + _context8.next = 6; return this.Model.get(id); case 6: - result = _context6.sent; + result = _context8.sent; userinfo; if (!(result.edit_uid !== 0 && result.edit_uid !== this.getUid())) { - _context6.next = 16; + _context8.next = 16; break; } userInst = _yapi2.default.getInst(_user2.default); - _context6.next = 12; + _context8.next = 12; return userInst.findById(result.edit_uid); case 12: - userinfo = _context6.sent; + userinfo = _context8.sent; data = { errno: result.edit_uid, data: { uid: result.edit_uid, username: userinfo.username } }; - _context6.next = 18; + _context8.next = 18; break; case 16: @@ -661,29 +800,217 @@ var interfaceController = function (_baseController) { ctx.websocket.on('close', function () { _this2.Model.upEditUid(id, 0).then(); }); - _context6.next = 25; + _context8.next = 25; break; case 22: - _context6.prev = 22; - _context6.t0 = _context6['catch'](0); + _context8.prev = 22; + _context8.t0 = _context8['catch'](0); - _yapi2.default.commons.log(_context6.t0, 'error'); + _yapi2.default.commons.log(_context8.t0, 'error'); case 25: case 'end': - return _context6.stop(); + return _context8.stop(); } } - }, _callee6, this, [[0, 22]]); + }, _callee8, this, [[0, 22]]); })); - function solveConflict(_x6) { - return _ref6.apply(this, arguments); + function solveConflict(_x8) { + return _ref8.apply(this, arguments); } return solveConflict; }() + }, { + key: 'addCat', + value: function () { + var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) { + var params, result; + return _regenerator2.default.wrap(function _callee9$(_context9) { + while (1) { + switch (_context9.prev = _context9.next) { + case 0: + _context9.prev = 0; + params = ctx.request.body; + + params = _yapi2.default.commons.handleParams(params, { + name: 'string', + project_id: 'number', + desc: 'string' + }); + + if (params.project_id) { + _context9.next = 5; + break; + } + + return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空')); + + case 5: + if (params.name) { + _context9.next = 7; + break; + } + + return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '名称不能为空')); + + case 7: + _context9.next = 9; + return this.catModel.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 = _context9.sent; + + ctx.body = _yapi2.default.commons.resReturn(result); + + _context9.next = 16; + break; + + case 13: + _context9.prev = 13; + _context9.t0 = _context9['catch'](0); + + ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t0.message); + + case 16: + case 'end': + return _context9.stop(); + } + } + }, _callee9, this, [[0, 13]]); + })); + + function addCat(_x9) { + return _ref9.apply(this, arguments); + } + + return addCat; + }() + }, { + key: 'upCat', + value: function () { + var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) { + var params, result; + return _regenerator2.default.wrap(function _callee10$(_context10) { + while (1) { + switch (_context10.prev = _context10.next) { + case 0: + _context10.prev = 0; + params = ctx.request.body; + _context10.next = 4; + return this.catModel.up(params.catid, { + name: params.cat_name, + desc: params.cat_desc, + up_time: _yapi2.default.commons.time() + }); + + case 4: + result = _context10.sent; + + ctx.body = _yapi2.default.commons.resReturn(result); + _context10.next = 11; + break; + + case 8: + _context10.prev = 8; + _context10.t0 = _context10['catch'](0); + + ctx.body = _yapi2.default.commons.resReturn(null, 400, _context10.t0.message); + + case 11: + case 'end': + return _context10.stop(); + } + } + }, _callee10, this, [[0, 8]]); + })); + + function upCat(_x10) { + return _ref10.apply(this, arguments); + } + + return upCat; + }() + }, { + key: 'delCat', + value: function () { + var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) { + var id, catData, auth, result; + return _regenerator2.default.wrap(function _callee11$(_context11) { + while (1) { + switch (_context11.prev = _context11.next) { + case 0: + _context11.prev = 0; + id = ctx.request.body.catid; + _context11.next = 4; + return this.catModel.get(id); + + case 4: + catData = _context11.sent; + + if (!catData) { + ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的分类"); + } + + if (!(catData.uid !== this.getUid())) { + _context11.next = 12; + break; + } + + _context11.next = 9; + return this.checkAuth(catData.project_id, 'project', 'danger'); + + case 9: + auth = _context11.sent; + + if (auth) { + _context11.next = 12; + break; + } + + return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '没有权限')); + + case 12: + _context11.next = 14; + return this.catModel.del(id); + + case 14: + result = _context11.sent; + _context11.next = 17; + return this.Model.delByCatid(id); + + case 17: + return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result)); + + case 20: + _context11.prev = 20; + _context11.t0 = _context11['catch'](0); + + _yapi2.default.commons.resReturn(null, 400, _context11.t0.message); + + case 23: + case 'end': + return _context11.stop(); + } + } + }, _callee11, this, [[0, 20]]); + })); + + function delCat(_x11) { + return _ref11.apply(this, arguments); + } + + return delCat; + }() }]); return interfaceController; }(_base2.default); diff --git a/server_dist/controllers/interfaceCol.js b/server_dist/controllers/interfaceCol.js index 793900a1..ad29ebf8 100644 --- a/server_dist/controllers/interfaceCol.js +++ b/server_dist/controllers/interfaceCol.js @@ -604,20 +604,24 @@ var interfaceColController = function (_baseController) { case 14: result = _context8.sent; + _context8.next = 17; + return this.caseModel.delByCol(id); + + case 17: return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result)); - case 18: - _context8.prev = 18; + case 20: + _context8.prev = 20; _context8.t0 = _context8['catch'](0); _yapi2.default.commons.resReturn(null, 400, _context8.t0.message); - case 21: + case 23: case 'end': return _context8.stop(); } } - }, _callee8, this, [[0, 18]]); + }, _callee8, this, [[0, 20]]); })); function delCol(_x8) { diff --git a/server_dist/controllers/project.js b/server_dist/controllers/project.js index c59cc6ee..1363b87b 100644 --- a/server_dist/controllers/project.js +++ b/server_dist/controllers/project.js @@ -658,30 +658,31 @@ var projectController = function (_baseController) { case 6: result = _context6.sent; + console.log(result); result = result.toObject(); delete result.members; - _context6.next = 11; + _context6.next = 12; return this.getProjectRole(params.id, 'project'); - case 11: + case 12: result.role = _context6.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context6.next = 18; + _context6.next = 19; break; - case 15: - _context6.prev = 15; + case 16: + _context6.prev = 16; _context6.t0 = _context6['catch'](3); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message); - case 18: + case 19: case 'end': return _context6.stop(); } } - }, _callee6, this, [[3, 15]]); + }, _callee6, this, [[3, 16]]); })); function get(_x7) { diff --git a/server_dist/models/interface.js b/server_dist/models/interface.js index b675cb94..64af4c45 100644 --- a/server_dist/models/interface.js +++ b/server_dist/models/interface.js @@ -52,6 +52,7 @@ var interfaceModel = function (_baseModel) { path: { type: String, required: true }, method: { type: String, required: true }, project_id: { type: Number, required: true }, + catid: { type: Number, required: true }, edit_uid: { type: Number, default: 0 }, status: { type: String, enum: ['undone', 'done'], default: 'undone' }, desc: String, @@ -143,10 +144,19 @@ var interfaceModel = function (_baseModel) { } }, { key: 'list', - value: function list(project_id) { + value: function list(project_id, select) { + select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time'; return this.model.find({ project_id: project_id - }).sort({ _id: -1 }).exec(); + }).select(select).sort({ _id: -1 }).exec(); + } + }, { + key: 'listByCatid', + value: function listByCatid(catid, select) { + select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time'; + return this.model.find({ + catid: catid + }).select(select).exec(); } }, { key: 'del', @@ -155,6 +165,13 @@ var interfaceModel = function (_baseModel) { _id: id }); } + }, { + key: 'delByCatid', + value: function delByCatid(id) { + return this.model.deleteMany({ + catid: id + }); + } }, { key: 'delByProjectId', value: function delByProjectId(id) { diff --git a/server_dist/models/interfaceCase.js b/server_dist/models/interfaceCase.js index e75cc85d..15c354e7 100644 --- a/server_dist/models/interfaceCase.js +++ b/server_dist/models/interfaceCase.js @@ -112,6 +112,13 @@ var interfaceCase = function (_baseModel) { project_id: id }); } + }, { + key: 'delByCol', + value: function delByCol(id) { + return this.model.deleteMany({ + col_id: id + }); + } }, { key: 'up', value: function up(id, data) { diff --git a/server_dist/models/interfaceCat.js b/server_dist/models/interfaceCat.js new file mode 100644 index 00000000..94d69187 --- /dev/null +++ b/server_dist/models/interfaceCat.js @@ -0,0 +1,114 @@ +'use strict'; + +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 _yapi = require('../yapi.js'); + +var _yapi2 = _interopRequireDefault(_yapi); + +var _base = require('./base.js'); + +var _base2 = _interopRequireDefault(_base); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/** + * 接口分类 + */ +var interfaceCat = function (_baseModel) { + (0, _inherits3.default)(interfaceCat, _baseModel); + + function interfaceCat() { + (0, _classCallCheck3.default)(this, interfaceCat); + return (0, _possibleConstructorReturn3.default)(this, (interfaceCat.__proto__ || (0, _getPrototypeOf2.default)(interfaceCat)).apply(this, arguments)); + } + + (0, _createClass3.default)(interfaceCat, [{ + key: 'getName', + value: function getName() { + return 'interface_cat'; + } + }, { + key: 'getSchema', + value: function getSchema() { + return { + name: { type: String, required: true }, + uid: { type: Number, required: true }, + project_id: { type: Number, required: true }, + desc: String, + add_time: Number, + up_time: Number + }; + } + }, { + key: 'save', + value: function save(data) { + var m = new this.model(data); + return m.save(); + } + }, { + key: 'get', + value: function get(id) { + return this.model.findOne({ + _id: id + }).exec(); + } + }, { + key: 'checkRepeat', + value: function checkRepeat(name) { + return this.model.count({ + name: name + }); + } + }, { + key: 'list', + value: function list(project_id) { + return this.model.find({ + project_id: project_id + }).exec(); + } + }, { + key: 'del', + value: function del(id) { + return this.model.deleteOne({ + _id: id + }); + } + }, { + key: 'delByProjectId', + value: function delByProjectId(id) { + return this.model.deleteMany({ + project_id: id + }); + } + }, { + key: 'up', + value: function up(id, data) { + data.up_time = _yapi2.default.commons.time(); + return this.model.update({ + _id: id + }, data); + } + }]); + return interfaceCat; +}(_base2.default); + +module.exports = interfaceCat; \ No newline at end of file diff --git a/server_dist/models/interfaceCol.1.js b/server_dist/models/interfaceCol.1.js new file mode 100644 index 00000000..1d9011e4 --- /dev/null +++ b/server_dist/models/interfaceCol.1.js @@ -0,0 +1,111 @@ +'use strict'; + +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 _yapi = require('../yapi.js'); + +var _yapi2 = _interopRequireDefault(_yapi); + +var _base = require('./base.js'); + +var _base2 = _interopRequireDefault(_base); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var interfaceCol = function (_baseModel) { + (0, _inherits3.default)(interfaceCol, _baseModel); + + function interfaceCol() { + (0, _classCallCheck3.default)(this, interfaceCol); + return (0, _possibleConstructorReturn3.default)(this, (interfaceCol.__proto__ || (0, _getPrototypeOf2.default)(interfaceCol)).apply(this, arguments)); + } + + (0, _createClass3.default)(interfaceCol, [{ + key: 'getName', + value: function getName() { + return 'interface_col'; + } + }, { + key: 'getSchema', + value: function getSchema() { + return { + name: { type: String, required: true }, + uid: { type: Number, required: true }, + project_id: { type: Number, required: true }, + desc: String, + add_time: Number, + up_time: Number + }; + } + }, { + key: 'save', + value: function save(data) { + var m = new this.model(data); + return m.save(); + } + }, { + key: 'get', + value: function get(id) { + return this.model.findOne({ + _id: id + }).exec(); + } + }, { + key: 'checkRepeat', + value: function checkRepeat(name) { + return this.model.count({ + name: name + }); + } + }, { + key: 'list', + value: function list(project_id) { + return this.model.find({ + project_id: project_id + }).exec(); + } + }, { + key: 'del', + value: function del(id) { + return this.model.deleteOne({ + _id: id + }); + } + }, { + key: 'delByProjectId', + value: function delByProjectId(id) { + return this.model.deleteMany({ + project_id: id + }); + } + }, { + key: 'up', + value: function up(id, data) { + data.up_time = _yapi2.default.commons.time(); + return this.model.update({ + _id: id + }, data); + } + }]); + return interfaceCol; +}(_base2.default); + +module.exports = interfaceCol; \ No newline at end of file diff --git a/server_dist/router.js b/server_dist/router.js index 8728b0f9..d03a558c 100644 --- a/server_dist/router.js +++ b/server_dist/router.js @@ -247,6 +247,26 @@ var routerConfig = { "action": "del", "path": "del", "method": "post" + }, { + action: 'listByCat', + path: 'list_cat', + method: 'get' + }, { + action: 'listByMenu', + path: 'list_menu', + method: 'get' + }, { + action: 'addCat', + path: 'add_cat', + method: 'post' + }, { + action: 'upCat', + path: 'up_cat', + method: 'post' + }, { + action: 'delCat', + path: 'del_cat', + method: 'post' }], "log": [{ "action": "list",