Skip to content

Commit 2e94af1

Browse files
committed
refactor : MongoDB 문법으로 forEach 문 대체
1 parent d90495c commit 2e94af1

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

server/apis/workspace/service.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,19 @@ export const info = async (workspaceId: number) => {
4141
if (!workspace)
4242
throw new InvalidWorkspaceError('존재하지 않는 워크스페이스에요 ^^');
4343

44-
const { name, users, moms } = workspace;
44+
const { name, users: usersInfo, moms: momsInfo } = workspace;
4545

46-
const usersInfo: Pick<User, 'name' | 'avatarUrl'>[] = [];
47-
const momsInfo: string[] = [];
46+
const users: Pick<User, 'name' | 'avatarUrl'>[] = await userModel.find(
47+
{
48+
id: { $in: usersInfo },
49+
},
50+
{ name: 1, avatarUrl: 1, _id: 0 },
51+
);
4852

49-
for await (const id of users) {
50-
const user = await userModel.findOne({ id });
53+
const moms: string[] = await momModel.find(
54+
{ id: { $in: momsInfo } },
55+
{ name: 1 },
56+
);
5157

52-
if (user) {
53-
const { name, avatarUrl } = user;
54-
usersInfo.push({ name, avatarUrl });
55-
}
56-
}
57-
58-
for await (const id of moms) {
59-
const mom = await momModel.findOne({ id });
60-
61-
if (mom) {
62-
const { name } = mom;
63-
momsInfo.push(name);
64-
}
65-
}
66-
67-
return { workspaceName: name, usersInfo, momsInfo };
58+
return { name, users, moms };
6859
};

0 commit comments

Comments
 (0)