Skip to content

Commit

Permalink
Fix: #253 mockAPI 추가 및 프로젝트 팀원 삭제 mswhandler 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-bear98 committed Oct 31, 2024
1 parent 78f7eee commit 7455328
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/mocks/mockAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function updateProjectUserRole(
projectUser.roleId = newRoleId;
}

// 프로젝트 유저 삭제
export function deleteProjectUser(projectId: Project['projectId'], userId: User['userId']) {
const projectUserIndex = PROJECT_USER_DUMMY.findIndex(
(projectUser) => projectUser.projectId === projectId && projectUser.userId === userId,
Expand Down Expand Up @@ -201,6 +202,17 @@ export function deleteAllTaskUser(taskId: Task['taskId']) {
}
}

// 일정과 특정 유저의 연결만 삭제
export function deleteTaskUser(taskId: Task['taskId'], userId: number) {
const taskUserIndex = TASK_USER_DUMMY.findIndex(
(taskUser) => taskUser.taskId === taskId && taskUser.userId === userId,
);

if (taskUserIndex !== -1) {
TASK_USER_DUMMY.splice(taskUserIndex, 1); // 특정 유저와의 연결 삭제
}
}

/* ===================== 일정(Task) 관련 처리 ===================== */

// 일정 추가
Expand Down
11 changes: 4 additions & 7 deletions src/mocks/services/projectServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
deleteAllTaskUser,
deleteProject,
deleteProjectUser,
deleteTaskUser,
findAllProject,
findAllProjectStatus,
findAllProjectUser,
Expand Down Expand Up @@ -383,17 +384,13 @@ const projectServiceHandler = [
try {
const statusIds = findAllProjectStatus(projectId).map((status) => status.statusId);

const taskIds: number[] = [];
statusIds.forEach((statusId) => {
const tasks = findAllTask(statusId);
tasks.forEach((task) => taskIds.push(task.taskId));
tasks.forEach((task) => {
deleteTaskUser(task.taskId, projectCoworkerId);
});
});

taskIds.forEach((taskId) => {
deleteAllTaskFileInMemory(taskId);
deleteAllTaskFile(taskId);
deleteAllTaskUser(taskId);
});
deleteProjectUser(projectId, projectCoworkerId);
} catch (error) {
console.error((error as Error).message);
Expand Down

0 comments on commit 7455328

Please sign in to comment.