Skip to content

Commit 3d1f7f4

Browse files
committed
feat : 워크스페이스의 유저, 회의록 목록 조회하기 API 구축
1 parent 0dac892 commit 3d1f7f4

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

server/apis/workspace/controller.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { OK } from '@constants/http-status';
66

77
const router = express.Router();
88

9+
/* POST: 워크스페이스 생성 */
910
router.post(
1011
'/',
1112
asyncWrapper(async (req: Request, res: Response) => {
@@ -17,6 +18,7 @@ router.post(
1718
}),
1819
);
1920

21+
/* POST: 워크스페이스 참여 */
2022
router.post(
2123
'/join',
2224
jwtAuthenticator,
@@ -29,4 +31,17 @@ router.post(
2931
}),
3032
);
3133

34+
/* GET: 특정 워크스페이스의 멤버, 회의록 목록 */
35+
router.get(
36+
'/:id',
37+
jwtAuthenticator,
38+
asyncWrapper(async (req: Request, res: Response) => {
39+
const { id: workspaceId } = req.params;
40+
41+
const workspaceInfo = await workspaceService.info(+workspaceId);
42+
43+
res.send({ ...workspaceInfo });
44+
}),
45+
);
46+
3247
export default router;

server/apis/workspace/service.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { v4 as uuidv4 } from 'uuid';
22
import workspaceModel from './model';
3-
import userModel from '@apis/user/model';
3+
import userModel, { User } from '@apis/user/model';
4+
import momModel from '@apis/mom/model';
45
import AuthorizationError from '@errors/authorization-error';
56
import InvalidJoinError from '@errors/invalid-join-error';
7+
import InvalidWorkspaceError from '@errors/invalid-workspace-error';
68

79
export const create = async (name: string) => {
810
if (!name) throw new Error('워크스페이스 이름을 입력하세요 ^^');
@@ -30,3 +32,37 @@ export const join = async (userId: number, code: string) => {
3032

3133
return { id, name, code };
3234
};
35+
36+
export const info = async (workspaceId: number) => {
37+
if (!workspaceId) throw new InvalidJoinError('잘못된 접근이에요 ^^');
38+
39+
const workspace = await workspaceModel.findOne({ id: workspaceId });
40+
41+
if (!workspace)
42+
throw new InvalidWorkspaceError('존재하지 않는 워크스페이스에요 ^^');
43+
44+
const { users, moms } = workspace;
45+
46+
const usersInfo: Pick<User, 'name' | 'avatarUrl'>[] = [];
47+
const momsInfo: string[] = [];
48+
49+
for await (const id of users) {
50+
const user = await userModel.findOne({ id });
51+
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 { usersInfo, momsInfo };
68+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import CustomError from '.';
2+
import { BAD_REQUEST } from '@constants/http-status';
3+
4+
class InvalidWorkspaceError extends CustomError {
5+
constructor(message = 'Unauthorized') {
6+
super(message, BAD_REQUEST);
7+
}
8+
}
9+
10+
export default InvalidWorkspaceError;

0 commit comments

Comments
 (0)