Skip to content

Commit

Permalink
Fix: #261 유저 전체검색 mswHandler 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-bear98 committed Nov 8, 2024
1 parent 4bc2039 commit cdfeffd
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/mocks/services/userServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const userServiceHandler = [

return HttpResponse.json(teamJoinStatusList);
}),

// 전체 유저 검색
http.get(`${BASE_URL}/user/search`, ({ request }) => {
const url = new URL(request.url);
Expand All @@ -199,19 +200,10 @@ const userServiceHandler = [
const userId = convertTokenToUserId(accessToken);
if (!userId) return new HttpResponse(null, { status: 401 });

// 전체 유저 목록 조회 (USER_DUMMY 사용)
const allUsers = USER_DUMMY;

// 유저 정보 취득
const searchUsers: SearchUser[] = [];
for (let i = 0; i < allUsers.length; i++) {
const user = allUsers[i];
if (!user) return new HttpResponse(null, { status: 404 });
searchUsers.push({ userId: user.userId, nickname: user.nickname });
}

// 접두사(nickname)와 일치하는 유저 정보 최대 5명 추출
const matchedSearchUsers = searchUsers.filter((user) => user.nickname.startsWith(nickname)).slice(0, 5);
const matchedSearchUsers = USER_DUMMY.filter((user) => user.nickname.startsWith(nickname))
.slice(0, 5)
.map((user) => ({ userId: user.userId, nickname: user.nickname }));

return HttpResponse.json(matchedSearchUsers);
}),
Expand Down

0 comments on commit cdfeffd

Please sign in to comment.