diff --git a/src/mocks/services/teamServiceHandler.ts b/src/mocks/services/teamServiceHandler.ts index 4fe8db51..64034780 100644 --- a/src/mocks/services/teamServiceHandler.ts +++ b/src/mocks/services/teamServiceHandler.ts @@ -7,6 +7,8 @@ import { TEAM_DUMMY, TEAM_USER_DUMMY, JWT_TOKEN_DUMMY, + TASK_USER_DUMMY, + TASK_FILE_DUMMY, } from '@mocks/mockData'; const BASE_URL = import.meta.env.VITE_BASE_URL; @@ -28,7 +30,7 @@ const teamServiceHandler = [ const accessToken = request.headers.get('Authorization'); const { teamId } = params; const [, payload] = JWT_TOKEN_DUMMY.split('.'); - // TODO: 실제 userId로 넣어주기 + // 실제 userId로 넣어주기 const userId = Number(payload.replace('mocked-payload-', '')); if (!accessToken) return new HttpResponse(null, { status: 401 }); @@ -39,30 +41,25 @@ const teamServiceHandler = [ TEAM_USER_DUMMY.length = 0; TEAM_USER_DUMMY.push(...filteredTeamUsers); + const projectIds = PROJECT_DUMMY.filter((project) => project.teamId === Number(teamId)).map( + (project) => project.projectId, + ); + const filteredProjectUsers = PROJECT_USER_DUMMY.filter( - (projectUser) => !(projectUser.projectId === Number(teamId) && projectUser.userId === Number(userId)), + (projectUser) => !(projectIds.includes(projectUser.projectId) && projectUser.userId === Number(userId)), ); PROJECT_USER_DUMMY.length = 0; PROJECT_USER_DUMMY.push(...filteredProjectUsers); - const projectIds = PROJECT_DUMMY.filter((project) => project.teamId === Number(teamId)).map( - (project) => project.projectId, - ); - - const filteredTasks = TASK_DUMMY.map((task) => { - const projectId = STATUS_DUMMY.find((status) => status.statusId === task.statusId)?.projectId; - if (projectId && projectIds.includes(projectId)) { - return { - ...task, - userId: task.userId.filter((id) => id !== Number(userId)), - }; - } - return task; + const filteredTaskUsers = TASK_USER_DUMMY.filter((taskUser) => { + const task = TASK_DUMMY.find((task) => task.taskId === taskUser.taskId); + const statusId = task ? task.statusId : undefined; + const projectId = statusId ? STATUS_DUMMY.find((status) => status.statusId === statusId)?.projectId : undefined; + return !(projectId && projectIds.includes(projectId) && taskUser.userId === Number(userId)); }); - - TASK_DUMMY.length = 0; - TASK_DUMMY.push(...filteredTasks); + TASK_USER_DUMMY.length = 0; + TASK_USER_DUMMY.push(...filteredTaskUsers); return new HttpResponse(null, { status: 204 }); }), @@ -82,26 +79,44 @@ const teamServiceHandler = [ TEAM_USER_DUMMY.length = 0; TEAM_USER_DUMMY.push(...filteredTeamUsers); - const projectIdsToDelete = new Set( - PROJECT_DUMMY.filter((project) => project.teamId === Number(teamId)).map((project) => project.projectId), + const projectIdsToDelete = PROJECT_DUMMY.filter((project) => project.teamId === Number(teamId)).map( + (project) => project.projectId, ); - const statusIdsToDelete = new Set( - STATUS_DUMMY.filter((status) => projectIdsToDelete.has(status.projectId)).map((status) => status.statusId), + const statusIdsToDelete = STATUS_DUMMY.filter((status) => projectIdsToDelete.includes(status.projectId)).map( + (status) => status.statusId, ); - const filteredProjects = PROJECT_DUMMY.filter((project) => !projectIdsToDelete.has(project.projectId)); + const filteredProjects = PROJECT_DUMMY.filter((project) => !projectIdsToDelete.includes(project.projectId)); PROJECT_DUMMY.length = 0; PROJECT_DUMMY.push(...filteredProjects); - const filteredStatuses = STATUS_DUMMY.filter((status) => !statusIdsToDelete.has(status.statusId)); + const filteredStatuses = STATUS_DUMMY.filter((status) => !statusIdsToDelete.includes(status.statusId)); STATUS_DUMMY.length = 0; STATUS_DUMMY.push(...filteredStatuses); - const filteredTasks = TASK_DUMMY.filter((task) => !statusIdsToDelete.has(task.statusId)); + const filteredTasks = TASK_DUMMY.filter((task) => !statusIdsToDelete.includes(task.statusId)); TASK_DUMMY.length = 0; TASK_DUMMY.push(...filteredTasks); + const filteredTaskFiles = TASK_FILE_DUMMY.filter((taskFile) => { + const task = TASK_DUMMY.find((task) => task.taskId === taskFile.taskId); + const statusId = task ? task.statusId : undefined; + const projectId = statusId ? STATUS_DUMMY.find((status) => status.statusId === statusId)?.projectId : undefined; + return !(projectId && projectIdsToDelete.includes(projectId)); + }); + TASK_FILE_DUMMY.length = 0; + TASK_FILE_DUMMY.push(...filteredTaskFiles); + + const filteredTaskUsers = TASK_USER_DUMMY.filter((taskUser) => { + const task = TASK_DUMMY.find((task) => task.taskId === taskUser.taskId); + const statusId = task ? task.statusId : undefined; + const projectId = statusId ? STATUS_DUMMY.find((status) => status.statusId === statusId)?.projectId : undefined; + return !(projectId && projectIdsToDelete.includes(projectId)); + }); + TASK_USER_DUMMY.length = 0; + TASK_USER_DUMMY.push(...filteredTaskUsers); + return new HttpResponse(null, { status: 204 }); }),