fix: fix no user type for admin user to group

This commit is contained in:
2025-03-01 10:30:12 +08:00
parent d2280f6b89
commit c482092961
3 changed files with 14 additions and 9 deletions

View File

@@ -30,12 +30,17 @@ app
const tokenAdmin = ctx.state.tokenAdmin;
const tokenUser = ctx.state.tokenUser;
const data = ctx.query.data;
const { orgId, userId, action } = data;
const { orgId, userId, username, action, role } = data;
const org = await Org.findByPk(orgId);
if (!org) {
ctx.throw('组织不存在');
}
const user = await User.findByPk(userId);
let user: User;
if (userId) {
user = await User.findByPk(userId);
} else if (username) {
user = await User.findOne({ where: { username } });
}
if (!user) {
ctx.throw('用户不存在');
}
@@ -44,7 +49,7 @@ app
}
const operateId = tokenUser.uid || tokenUser.id;
if (action === 'add') {
await org.addUser(user, { needPermission: true, role: 'user', operateId, isAdmin: !!tokenAdmin });
await org.addUser(user, { needPermission: true, role: role || 'user', operateId, isAdmin: !!tokenAdmin });
} else if (action === 'remove') {
await org.removeUser(user, { needPermission: true, operateId, isAdmin: !!tokenAdmin });
} else {