Skip to content

Commit

Permalink
Fix: #120 팀 삭제 API 일정 파일 & 유저 삭제 추가 및 팀 탈퇴API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-bear98 committed Sep 19, 2024
1 parent 7191a3a commit 34e775e
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions src/mocks/services/teamServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 });

Expand All @@ -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 });
}),
Expand All @@ -82,26 +79,44 @@ const teamServiceHandler = [
TEAM_USER_DUMMY.length = 0;
TEAM_USER_DUMMY.push(...filteredTeamUsers);

const projectIdsToDelete = new Set<number>(
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<number>(
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 });
}),

Expand Down

0 comments on commit 34e775e

Please sign in to comment.