feat: add project init env col cat

This commit is contained in:
suxiaoxin 2017-08-23 14:28:27 +08:00
parent 3440492be2
commit d55485b56a
2 changed files with 113 additions and 61 deletions

View File

@ -106,11 +106,32 @@ class projectController extends baseController {
icon: params.icon,
color: params.color,
add_time: yapi.commons.time(),
up_time: yapi.commons.time()
up_time: yapi.commons.time(),
env: [{ name: 'local', domain: 'http://127.0.0.1' }]
};
try {
let result = await this.Model.save(data);
let colInst = yapi.getInst(interfaceColModel);
let catInst = yapi.getInst(interfaceCatModel);
if (result._id) {
await colInst.save({
name: '公共测试集',
project_id: result._id,
desc: '公共测试集',
uid: this.getUid(),
add_time: yapi.commons.time(),
up_time: yapi.commons.time()
})
await catInst.save({
name: '公共分类',
project_id: result._id,
desc: '公共分类',
uid: this.getUid(),
add_time: yapi.commons.time(),
up_time: yapi.commons.time()
})
}
let username = this.getUsername();
yapi.commons.saveLog({
content: `用户${username}添加了项目${params.name}`,
@ -160,7 +181,7 @@ class projectController extends baseController {
params.role = params.role === 'owner' ? 'owner' : 'dev';
let userdata = await this.getUserdata(params.member_uid, params.role);
if(userdata === null){
if (userdata === null) {
return ctx.body = yapi.commons.resReturn(null, 400, '成员uid不存在')
}
@ -217,7 +238,7 @@ class projectController extends baseController {
let result = await this.Model.delMember(params.id, params.member_uid);
let username = this.getUsername();
let project = await this.Model.get(params.id);
let member = await yapi.getInst(userModel).findById(params.member_uid);
let member = await yapi.getInst(userModel).findById(params.member_uid);
yapi.commons.saveLog({
content: `用户${username}删除了项目${project.name}中的成员${member.username}`,
type: 'project',
@ -234,11 +255,11 @@ class projectController extends baseController {
}
async getUserdata(uid, role){
async getUserdata(uid, role) {
role = role || 'dev';
let userInst = yapi.getInst(userModel);
let userData = await userInst.findById(uid);
if(!userData){
if (!userData) {
return null;
}
return {
@ -292,7 +313,7 @@ class projectController extends baseController {
}
try {
let result = await this.Model.getBaseInfo(params.id);
if(!result){
if (!result) {
return ctx.body = yapi.commons.resReturn(null, 400, '不存在的项目');
}
result = result.toObject();
@ -324,19 +345,19 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
}
let auth =await this.checkAuth(group_id, 'group', 'edit')
let auth = await this.checkAuth(group_id, 'group', 'edit')
try {
let result = await this.Model.list(group_id, auth);
let follow = await this.followModel.list(this.getUid());
let uids = [];
result.forEach((item, index) => {
result[index] = item.toObject();
let f = _.find(follow, (fol)=>{
let f = _.find(follow, (fol) => {
return fol.projectid === item._id
})
if(f){
if (f) {
result[index].follow = true;
}else{
} else {
result[index].follow = false;
}
if (uids.indexOf(item.uid) === -1) {
@ -404,7 +425,7 @@ class projectController extends baseController {
* @returns {Object}
* @example
*/
async changeMemberRole(ctx){
async changeMemberRole(ctx) {
let params = ctx.request.body;
let projectInst = yapi.getInst(projectModel);
if (!params.member_uid) {
@ -454,23 +475,23 @@ class projectController extends baseController {
* @returns {Object}
* @example ./api/project/upset
*/
async upSet(ctx){
async upSet(ctx) {
let id = ctx.request.body.id;
let data = {};
data.color = ctx.request.body.color;
data.icon = ctx.request.body.icon;
if(!id){
if (!id) {
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
}
try{
try {
let result = await this.Model.up(id, data);
ctx.body = yapi.commons.resReturn(result);
}catch(e){
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
try{
this.followModel.updateById(this.getUid(),id,data).then();
}catch(e){
try {
this.followModel.updateById(this.getUid(), id, data).then();
} catch (e) {
yapi.commons.log(e, 'error'); // eslint-disable-line
}
}
@ -535,12 +556,12 @@ class projectController extends baseController {
if (params.name) data.name = params.name;
if (params.desc) data.desc = params.desc;
if (params.basepath ) {
if (params.basepath) {
data.basepath = params.basepath;
}
if (params.env) data.env = params.env;
if(params.color) data.color = params.color;
if(params.icon) data.icon = params.icon;
if (params.color) data.color = params.color;
if (params.icon) data.icon = params.icon;
let result = await this.Model.up(id, data);
let username = this.getUsername();
yapi.commons.saveLog({
@ -556,37 +577,37 @@ class projectController extends baseController {
}
}
/**
* 修改项目头像
* @interface /project/upset
* @method POST
* @category project
* @foldnumber 10
* @param {Number} id
* @param {String} color
* @param {String} icon
* @return {Object}
*/
async upSet(ctx){
let id = ctx.request.body.id;
let data = {};
data.color = ctx.request.body.color;
data.icon = ctx.request.body.icon;
if(!id){
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
}
try{
let result = await this.Model.up(id, data);
ctx.body = yapi.commons.resReturn(result);
}catch(e){
ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
try{
this.followModel.updateById(this.getUid(),id,data).then();
}catch(e){
yapi.commons.log(e, 'error'); // eslint-disable-line
}
}
/**
* 修改项目头像
* @interface /project/upset
* @method POST
* @category project
* @foldnumber 10
* @param {Number} id
* @param {String} color
* @param {String} icon
* @return {Object}
*/
async upSet(ctx) {
let id = ctx.request.body.id;
let data = {};
data.color = ctx.request.body.color;
data.icon = ctx.request.body.icon;
if (!id) {
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
}
try {
let result = await this.Model.up(id, data);
ctx.body = yapi.commons.resReturn(result);
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
try {
this.followModel.updateById(this.getUid(), id, data).then();
} catch (e) {
yapi.commons.log(e, 'error'); // eslint-disable-line
}
}
/**
* 模糊搜索项目名称或者组名称
@ -663,7 +684,7 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 401, '项目id不存在');
}
const arr = JSON.stringify(count.map(function(item) {
const arr = JSON.stringify(count.map(function (item) {
// 返回的json模板数据: item.res_body
const mockData = Mock.mock(
yapi.commons.json_parse(item.res_body)
@ -704,7 +725,7 @@ class projectController extends baseController {
});
}
module.exports = run;`
.trim();
.trim();
return ctx.body = res;
}
}

View File

@ -149,7 +149,7 @@ var projectController = function (_baseController) {
key: 'add',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var params, checkRepeat, data, result, username;
var params, checkRepeat, data, result, colInst, catInst, username;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
@ -233,7 +233,8 @@ var projectController = function (_baseController) {
icon: params.icon,
color: params.color,
add_time: _yapi2.default.commons.time(),
up_time: _yapi2.default.commons.time()
up_time: _yapi2.default.commons.time(),
env: [{ name: 'local', domain: 'http://127.0.0.1' }]
};
_context.prev = 20;
_context.next = 23;
@ -241,6 +242,36 @@ var projectController = function (_baseController) {
case 23:
result = _context.sent;
colInst = _yapi2.default.getInst(_interfaceCol2.default);
catInst = _yapi2.default.getInst(_interfaceCat2.default);
if (!result._id) {
_context.next = 31;
break;
}
_context.next = 29;
return colInst.save({
name: '公共测试集',
project_id: result._id,
desc: '公共测试集',
uid: this.getUid(),
add_time: _yapi2.default.commons.time(),
up_time: _yapi2.default.commons.time()
});
case 29:
_context.next = 31;
return catInst.save({
name: '公共分类',
project_id: result._id,
desc: '公共分类',
uid: this.getUid(),
add_time: _yapi2.default.commons.time(),
up_time: _yapi2.default.commons.time()
});
case 31:
username = this.getUsername();
_yapi2.default.commons.saveLog({
@ -254,21 +285,21 @@ var projectController = function (_baseController) {
icon: params.icon
});
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 32;
_context.next = 39;
break;
case 29:
_context.prev = 29;
case 36:
_context.prev = 36;
_context.t1 = _context['catch'](20);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t1.message);
case 32:
case 39:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[20, 29]]);
}, _callee, this, [[20, 36]]);
}));
function add(_x) {