From 535f6355605d66c36fe2c3d3599c35409946b1c2 Mon Sep 17 00:00:00 2001 From: zwjamnsss Date: Wed, 11 Oct 2017 10:50:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B9=E5=8F=98=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=82=AE=E7=AE=B1bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/group.js | 8 +------- server/controllers/project.js | 8 +------- server/controllers/user.js | 16 +++++++++++++++- server/models/group.js | 17 ++++++++++++++++- server/models/project.js | 15 ++++++++++++++- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/server/controllers/group.js b/server/controllers/group.js index 03334bfb..e30658e4 100755 --- a/server/controllers/group.js +++ b/server/controllers/group.js @@ -293,13 +293,7 @@ class groupController extends baseController { try { let groupInst = yapi.getInst(groupModel); let group = await groupInst.get(params.id); - const members = []; - for(let i = 0, len = group.members.length; i < len; i++) { - let item = group.members[i]; - let member = await this.getUserdata(item.uid, item.role) - members.push(member) - } - ctx.body = yapi.commons.resReturn(members); + ctx.body = yapi.commons.resReturn(group.members); } catch (e) { ctx.body = yapi.commons.resReturn(null, 402, e.message); } diff --git a/server/controllers/project.js b/server/controllers/project.js index 7eb7a80c..afff1936 100755 --- a/server/controllers/project.js +++ b/server/controllers/project.js @@ -306,13 +306,7 @@ class projectController extends baseController { try { let project = await this.Model.get(params.id); - const members = []; - for(let i = 0, len = project.members.length; i < len; i++) { - let item = project.members[i]; - let member = await this.getUserdata(item.uid, item.role) - members.push(member) - } - ctx.body = yapi.commons.resReturn(members); + ctx.body = yapi.commons.resReturn(project.members); } catch (e) { ctx.body = yapi.commons.resReturn(null, 402, e.message); } diff --git a/server/controllers/user.js b/server/controllers/user.js index 5397b88b..1333616f 100755 --- a/server/controllers/user.js +++ b/server/controllers/user.js @@ -469,6 +469,11 @@ class userController extends baseController { return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空'); } + let userData = await userInst.findById(id); + if (!userData) { + return ctx.body = yapi.commons.resReturn(null, 400, 'uid不存在'); + } + let data = { up_time: yapi.commons.time() }; @@ -483,8 +488,17 @@ class userController extends baseController { } } - let result = await userInst.update(id, data); + let member = { + uid: id, + username: data.username || userData.username, + email: data.email || userData.email + } + let groupInst = yapi.getInst(groupModel); + groupInst.updateMember(member) + let projectInst = yapi.getInst(projectModel); + projectInst.updateMember(member) + let result = await userInst.update(id, data); ctx.body = yapi.commons.resReturn(result); } catch (e) { ctx.body = yapi.commons.resReturn(null, 402, e.message); diff --git a/server/models/group.js b/server/models/group.js index 9218c6d3..30399283 100755 --- a/server/models/group.js +++ b/server/models/group.js @@ -17,7 +17,9 @@ class groupModel extends baseModel { members: [ { uid: Number, - role: {type: String, enum:['owner', 'dev']} + role: {type: String, enum:['owner', 'dev']}, + username: String, + email: String } ] }; @@ -34,6 +36,19 @@ class groupModel extends baseModel { }).exec(); } + updateMember(data) { + return this.model.update( + { + "members.uid": data.uid + }, { + "$set": { + "members.$.username": data.username, + "members.$.email": data.email + } + }, { multi: true } + ); + } + getByPrivateUid(uid){ return this.model.findOne({ uid: uid, diff --git a/server/models/project.js b/server/models/project.js index 76bba3c4..451a3ca5 100755 --- a/server/models/project.js +++ b/server/models/project.js @@ -15,7 +15,7 @@ class projectModel extends baseModel { group_id: { type: Number, required: true }, project_type: {type:String, required: true, enum: ['public', 'private']}, members: [ - {uid: Number, role: {type: String, enum:['owner', 'dev']}} + {uid: Number, role: {type: String, enum:['owner', 'dev']},username: String, email: String} ], env: [ { name: String, domain: String } @@ -27,6 +27,19 @@ class projectModel extends baseModel { }; } + updateMember(data) { + return this.model.update( + { + 'members.uid': data.uid + }, { + "$set": { + "members.$.username": data.username, + "members.$.email": data.email + } + } + ); + } + save(data) { let m = new this.model(data); return m.save();