@mindbase/express-admin 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/service/UserService.ts +37 -2
package/package.json
CHANGED
package/service/UserService.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { eq, and, like, or, desc, count, isNull } from "drizzle-orm";
|
|
1
|
+
import { eq, and, like, or, desc, count, isNull, sql } from "drizzle-orm";
|
|
2
2
|
import { users } from "@mindbase/express-auth";
|
|
3
3
|
import { md5 } from "@mindbase/express-auth";
|
|
4
|
+
import { userRoles, roles } from "@mindbase/express-auth";
|
|
4
5
|
|
|
5
6
|
let _db: any;
|
|
6
7
|
|
|
@@ -127,8 +128,42 @@ export async function listUsers(options: {
|
|
|
127
128
|
.offset((page - 1) * pageSize)
|
|
128
129
|
.execute();
|
|
129
130
|
|
|
131
|
+
// 查询用户角色关联
|
|
132
|
+
const userIds = list.map((u: any) => u.id);
|
|
133
|
+
const rolesData = userIds.length > 0
|
|
134
|
+
? await db
|
|
135
|
+
.select({
|
|
136
|
+
userId: userRoles.userId,
|
|
137
|
+
roleId: roles.id,
|
|
138
|
+
roleName: roles.name,
|
|
139
|
+
roleCode: roles.code,
|
|
140
|
+
})
|
|
141
|
+
.from(userRoles)
|
|
142
|
+
.innerJoin(roles, eq(userRoles.roleId, roles.id))
|
|
143
|
+
.where(sql`${userRoles.userId} IN ${sql.raw(`(${userIds.join(',')})`)}`)
|
|
144
|
+
.execute()
|
|
145
|
+
: [];
|
|
146
|
+
|
|
147
|
+
// 组装角色数据
|
|
148
|
+
const userRolesMap: Record<number, any[]> = {};
|
|
149
|
+
rolesData.forEach((r: any) => {
|
|
150
|
+
if (!userRolesMap[r.userId]) {
|
|
151
|
+
userRolesMap[r.userId] = [];
|
|
152
|
+
}
|
|
153
|
+
userRolesMap[r.userId].push({
|
|
154
|
+
id: r.roleId,
|
|
155
|
+
name: r.roleName,
|
|
156
|
+
code: r.roleCode,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const listWithRoles = list.map((u: any) => ({
|
|
161
|
+
...u,
|
|
162
|
+
roles: userRolesMap[u.id] || [],
|
|
163
|
+
}));
|
|
164
|
+
|
|
130
165
|
return {
|
|
131
|
-
list,
|
|
166
|
+
list: listWithRoles,
|
|
132
167
|
total,
|
|
133
168
|
page,
|
|
134
169
|
pageSize,
|