mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
fix: 改变用户邮箱bug
This commit is contained in:
parent
16a4fa1bcc
commit
535f635560
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user