Skip to content

Commit

Permalink
Feat: #196 Mock에 정의한 타입 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Oct 16, 2024
1 parent 44d7f4f commit b38ef33
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
10 changes: 5 additions & 5 deletions src/mocks/mockAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
USER_DUMMY,
} from '@mocks/mockData';

import type { FileInfo, TaskUser, UploadTaskFile } from '@mocks/mockData';
import type { Role } from '@/types/RoleType';
import type { User } from '@/types/UserType';
import type { Project } from '@/types/ProjectType';
import type { ProjectStatus } from '@/types/ProjectStatusType';
import type { Task, TaskUpdateForm } from '@/types/TaskType';
import type { TaskFileForMemory, TaskUser, UploadTaskFile } from '@/types/MockType';

/* ===================== 역할(Role) 관련 처리 ===================== */

Expand Down Expand Up @@ -157,25 +157,25 @@ export function reorderTaskByStatus(statusId: ProjectStatus['statusId']) {
/* =============== 업로드 파일 임시 저장 관련 처리 =============== */

// 업로드된 일정 파일을 메모리 임시 저장
export function saveTaskFileInMemory(taskFile: FileInfo) {
export function saveTaskFileInMemory(taskFile: TaskFileForMemory) {
FILE_DUMMY.push(taskFile);
}

// 임시 저장된 일정 파일 다운로드
export function downloadTaskFileInMemory(uploadName: FileInfo['uploadName']) {
export function downloadTaskFileInMemory(uploadName: TaskFileForMemory['uploadName']) {
return FILE_DUMMY.find((file) => file.uploadName === uploadName);
}

// 임시 저장된 일정 파일 삭제
export function deleteTaskFileInMemory(taskId: FileInfo['taskId'], fileId: FileInfo['fileId']) {
export function deleteTaskFileInMemory(taskId: TaskFileForMemory['taskId'], fileId: TaskFileForMemory['fileId']) {
const fileIndex = FILE_DUMMY.findIndex((file) => file.taskId === taskId && file.fileId === fileId);

if (fileIndex === -1) throw new Error('일정 파일(In memory)을 찾을 수 없습니다.');
FILE_DUMMY.splice(fileIndex, 1);
}

// 임시 저장된 특정 일정의 모든 파일 삭제
export function deleteAllTaskFileInMemory(taskId: FileInfo['taskId']) {
export function deleteAllTaskFileInMemory(taskId: TaskFileForMemory['taskId']) {
const filteredFile = FILE_DUMMY.filter((file) => file.taskId !== taskId);
if (filteredFile.length !== FILE_DUMMY.length) {
FILE_DUMMY.length = 0;
Expand Down
35 changes: 2 additions & 33 deletions src/mocks/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,7 @@ import type { Project } from '@/types/ProjectType';
import type { ProjectStatus } from '@/types/ProjectStatusType';
import type { Task } from '@/types/TaskType';
import type { Role } from '@/types/RoleType';

type TeamUser = {
teamId: number;
userId: number;
roleId: number;
isPendingApproval: boolean;
};

type ProjectUser = {
projectId: number;
userId: number;
roleId: number;
};

export type TaskUser = {
taskId: number;
userId: number;
};

export type UploadTaskFile = {
fileId: number;
taskId: number;
fileName: string;
uploadName: string;
};

export type FileInfo = {
fileId: number;
taskId: number;
file: Blob;
uploadName: string;
};
import type { ProjectUser, TaskFileForMemory, TaskUser, TeamUser, UploadTaskFile } from '@/types/MockType';

export const JWT_TOKEN_DUMMY = 'mocked-header.mocked-payload-4.mocked-signature';

Expand Down Expand Up @@ -817,7 +786,7 @@ export const TASK_FILE_DUMMY: UploadTaskFile[] = [
];

// MSW 파일 임시 저장을 위한 변수
export const FILE_DUMMY: FileInfo[] = [
export const FILE_DUMMY: TaskFileForMemory[] = [
{
fileId: 1,
taskId: 1,
Expand Down
31 changes: 31 additions & 0 deletions src/types/MockType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export type TeamUser = {
teamId: number;
userId: number;
roleId: number;
isPendingApproval: boolean;
};

export type ProjectUser = {
projectId: number;
userId: number;
roleId: number;
};

export type TaskUser = {
taskId: number;
userId: number;
};

export type UploadTaskFile = {
fileId: number;
taskId: number;
fileName: string;
uploadName: string;
};

export type TaskFileForMemory = {
fileId: number;
taskId: number;
file: Blob;
uploadName: string;
};

0 comments on commit b38ef33

Please sign in to comment.