The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/api/server/helpers/addUserToFileObj.ts

19 lines
605 B

import type { IUpload, IUser } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';
export async function addUserToFileObj(files: IUpload[]): Promise<(IUpload & { user?: Pick<IUser, '_id' | 'name' | 'username'> })[]> {
const uids = files.map(({ userId }) => userId).filter(Boolean);
const users = await Users.findByIds(uids, { projection: { name: 1, username: 1 } }).toArray();
return files.map((file) => {
const user = users.find(({ _id: userId }) => file.userId && userId === file.userId);
if (!user) {
return file;
}
return {
...file,
user,
};
});
}