Implement batch user retrieval in AdminController and update routes
- Added a new method `getUsers` in AdminController to handle batch retrieval of user information based on hashed IDs. - Updated adminRouter to include a new route for batch user retrieval. - Enhanced AdminService with a method to fetch user details by hashed IDs, ensuring proper access control. - Updated localization files to include the new "username" field for user connections in both German and English. - Modified ServicesStatusView to utilize the new batch user retrieval for displaying usernames alongside connection counts.
This commit is contained in:
@@ -441,6 +441,30 @@ class AdminService {
|
||||
return { id: user.hashedId, username: user.username, active: user.active, registrationDate: user.registrationDate };
|
||||
}
|
||||
|
||||
async getUsersByHashedIds(requestingHashedUserId, targetHashedIds) {
|
||||
if (!(await this.hasUserAccess(requestingHashedUserId, 'useradministration'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
if (!Array.isArray(targetHashedIds) || targetHashedIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const users = await User.findAll({
|
||||
where: { hashedId: { [Op.in]: targetHashedIds } },
|
||||
attributes: ['id', 'hashedId', 'username', 'active', 'registrationDate']
|
||||
});
|
||||
// Erstelle ein Map für schnellen Zugriff
|
||||
const userMap = {};
|
||||
users.forEach(user => {
|
||||
userMap[user.hashedId] = {
|
||||
id: user.hashedId,
|
||||
username: user.username,
|
||||
active: user.active,
|
||||
registrationDate: user.registrationDate
|
||||
};
|
||||
});
|
||||
return userMap;
|
||||
}
|
||||
|
||||
async updateUser(requestingHashedUserId, targetHashedId, data) {
|
||||
if (!(await this.hasUserAccess(requestingHashedUserId, 'useradministration'))) {
|
||||
throw new Error('noaccess');
|
||||
|
||||
Reference in New Issue
Block a user