Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ model UserAlarm {

//시간 관련
alarmDate DateTime @map("alarm_date") @db.DateTime // 알람 보낼 시간(기본값: 24시간 후)
createdAt DateTime @default(now()) @map("created_at") @db.DateTime // 알람 생성 시간
createdAt DateTime @default(now()) @map("created_at") @db.DateTime // 알람 생성 시간 한국시간으로

// 관계 설정 (Relations)
user User @relation("UserAlarms", fields: [userId], references: [id], onDelete: Restrict) // 유저와 연결
Expand Down
133 changes: 82 additions & 51 deletions src/controllers/task.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class TaskController {
// 완료된 과제 조회
async getCompletedTasks(req, res, next) {
try {
const userId = req.user.id;
const userId = req.user.id;

const result = await taskService.getCompletedTasks(userId);

res.status(200).json({
Expand All @@ -22,29 +22,30 @@ class TaskController {
}
}

// 과제 생성
async createTask(req, res, next) {
try {
const userId = req.user.id; // 사용자 ID 가져오기
const taskRequest = createTaskRequestDTO(req.body);
const result = await taskService.registerTask(taskRequest);

const result = await taskService.registerTask(userId, taskRequest);

res.status(201).json({
resultType: "SUCCESS",
message: "요청이 처리되어서 새로운 과제가 생성되었습니다.",
data: result
});
} catch (error) {
next(error);
next(error);
}
}


// 과제 수정
async updateTask(req, res, next) {
try {
const { taskId } = req.params;
const taskRequest = updateTaskRequestDTO(req.body);

const result = await taskService.modifyTask(parseInt(taskId), taskRequest);

res.status(200).json({
Expand Down Expand Up @@ -80,9 +81,9 @@ class TaskController {
const task = await taskService.getTaskDetail(parseInt(taskId));

res.status(200).json({
resultType: "SUCCESS",
message: "서버가 요청을 성공적으로 처리하였습니다.",
data: taskDetailResponseDTO(task)
resultType: "SUCCESS",
message: "서버가 요청을 성공적으로 처리하였습니다.",
data: taskDetailResponseDTO(task)
});
} catch (error) {
next(error);
Expand All @@ -92,65 +93,65 @@ class TaskController {
// 과제 목록 조회
async getTasks(req, res, next) {
try {
console.log("쿼리 내용:", req.query);
const queryParams = {
type: req.query.type,
sort: req.query.sort,
folderId: req.query.folderId || req.query.folder_id || req.query.folderld,
};
const userId = req.user.id;

const tasks = await taskService.getTaskList(userId, queryParams);

res.status(200).json({
resultType: "SUCCESS",
message: "서버가 요청을 성공적으로 처리하였습니다.",
data: taskListResponseDTO(tasks)
});
console.log("쿼리 내용:", req.query);

const queryParams = {
type: req.query.type,
sort: req.query.sort,
folderId: req.query.folderId || req.query.folder_id || req.query.folderld,
};
const userId = req.user.id;

const tasks = await taskService.getTaskList(userId, queryParams);

res.status(200).json({
resultType: "SUCCESS",
message: "서버가 요청을 성공적으로 처리하였습니다.",
data: taskListResponseDTO(tasks)
});
} catch (error) {
next(error);
next(error);
}
}

// 우선 순위 변경
async updateTaskPriorities(req, res, next) {
try {
const userId = req.user.id;
const { orderedTasks } = req.body;
const userId = req.user.id;
const { orderedTasks } = req.body;

await taskService.updatePriorities(userId, orderedTasks);
await taskService.updatePriorities(userId, orderedTasks);

res.status(200).json({
resultType: "SUCCESS",
message: "과제 우선순위가 일괄 변경되었습니다.",
data: null
});
res.status(200).json({
resultType: "SUCCESS",
message: "과제 우선순위가 일괄 변경되었습니다.",
data: null
});
} catch (error) {
next(error);
next(error);
}
}

// 팀원 정보 수정
async updateTeamMember(req, res, next) {
try {
const {taskId, memberId} = req.params;
const {role} = req.body;
const { taskId, memberId } = req.params;
const { role } = req.body;

const result = await taskService.modifyMemberRole(
parseInt(taskId),
parseInt(memberId),
role
parseInt(taskId),
parseInt(memberId),
role
);

res.status(200).json({
resultType: "SUCCESS",
message: "요청이 성공적으로 처리되었습니다.",
data: {
member_id: result.id,
user_id: result.userId,
task_id: result.taskId,
role: result.role ? 1 : 0,
member_id: result.id,
user_id: result.userId,
task_id: result.taskId,
role: result.role ? 1 : 0,
}
});
} catch (error) {
Expand Down Expand Up @@ -196,7 +197,7 @@ class TaskController {
const responseData = {
resultType: 'SUCCESS',
message: '마감 기한이 변경되었습니다.',
data: {
data: {
sub_task_id: updatedTask.id,
end_date: updatedTask.endDate.toISOString().split('T')[0]
}
Expand All @@ -210,13 +211,13 @@ class TaskController {
status: error.status,
errorCode: error.errorCode
});

// 에러 객체에 상태 코드가 없으면 500으로 설정
if (!error.status) {
error.status = 500;
error.errorCode = 'INTERNAL_SERVER_ERROR';
}

next(error);
}
}
Expand Down Expand Up @@ -250,7 +251,7 @@ class TaskController {
statusCode: error.statusCode || error.status,
errorCode: error.errorCode
});

// 에러 객체에 상태 코드가 없으면 500으로 설정
if (!error.statusCode && !error.status) {
error.statusCode = 500;
Expand All @@ -259,7 +260,7 @@ class TaskController {
// 이전 버전과의 호환성을 위해 status가 있으면 statusCode로 복사
error.statusCode = error.status;
}

next(error);
}
}
Expand All @@ -284,6 +285,36 @@ class TaskController {
next(error);
}
}

// 초대 코드로 팀 참여
async joinTaskByInviteCode(req, res, next) {
try {
const userId = req.user.id;
const { inviteCode } = req.body;

if (!inviteCode || typeof inviteCode !== 'string') {
return res.status(400).json({
resultType: "FAIL",
message: "초대 코드는 필수입니다.",
data: null
});
}

const result = await taskService.joinTaskByInviteCode(userId, inviteCode);

res.status(200).json({
resultType: "SUCCESS",
message: "팀에 성공적으로 참여했습니다.",
data: {
task_id: result.taskId,
task_title: result.taskTitle,
member_id: result.memberId
}
});
} catch (error) {
next(error);
}
}
}


Expand Down
80 changes: 40 additions & 40 deletions src/dtos/task.dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export const createTaskRequestDTO = (data) => {
title: data.title,
folderId: data.folderId,
deadline: new Date(data.deadline),
type: data.type === "팀" ? "TEAM" : "PERSONAL",
type: data.type === "팀" ? "TEAM" : "PERSONAL",
status: "PENDING",
subTasks: (data.subTasks || []).map(st => ({
title: st.title,
endDate: new Date(st.deadline)
endDate: new Date(st.deadline)
})),
references: data.references || []
};
Expand Down Expand Up @@ -42,56 +42,56 @@ export const taskDetailResponseDTO = (task) => {
const progressRate = totalSubTasks > 0 ? Math.round((completedSubTasks / totalSubTasks) * 100) : 0;

return {
taskId: task.id,
title: task.title,
type: task.type === "TEAM" ? "TEAM" : "INDIVIDUAL",
deadline: task.deadline.toISOString().split('T')[0],
dDay: dDay,
progressRate: progressRate,
taskId: task.id,
title: task.title,
type: task.type === "TEAM" ? "TEAM" : "INDIVIDUAL",
deadline: task.deadline.toISOString().split('T')[0],
dDay: dDay,
progressRate: progressRate,
subTasks: task.subTasks?.map(st => ({
subTaskId: st.id,
title: st.title,
deadline: st.endDate?.toISOString().split('T')[0] || null,
status: st.status === 'COMPLETED' ? 'COMPLETED' : 'PROGRASS',
subTaskId: st.id,
title: st.title,
deadline: st.endDate?.toISOString().split('T')[0] || null,
status: st.status === 'COMPLETED' ? 'COMPLETED' : 'PROGRASS',
isAlarm: st.isAlarm || false,
commentCount: st._count?.comments || 0,
assigneeName: st.assigneeName || "PENDING"
commentCount: st._count?.comments || 0,
assigneeName: st.assigneeName || "PENDING"
})) || [],
communications: task.communications?.map(c => ({
name: c.name,
url: c.url
name: c.name,
url: c.url
})) || [],
meetingLogs: task.logs?.map(log => ({
logId: log.id,
title: log.title
})) || [],
references: task.references?.map(r => ({
name: r.name,
url: r.url
name: r.name,
url: r.url
})) || []
};
};

export const taskListResponseDTO = (tasks) => {
return tasks.map(task => {
// D-Day 계산
const today = new Date();
const deadlineDate = new Date(task.deadline);
const diffTime = deadlineDate - today;
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
const dDay = diffDays === 0 ? "D-Day" : diffDays > 0 ? `D-${diffDays}` : `D+${Math.abs(diffDays)}`;
return tasks.map(task => {
// D-Day 계산
const today = new Date();
const deadlineDate = new Date(task.deadline);
const diffTime = deadlineDate - today;
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
const dDay = diffDays === 0 ? "D-Day" : diffDays > 0 ? `D-${diffDays}` : `D+${Math.abs(diffDays)}`;

return {
taskId: task.id,
folderId: task.folderId,
folderTitle: task.folder?.title || "PENDING",
title: task.title,
type: task.type === "TEAM" ? "TEAM" : "INDIVIDUAL",
deadline: task.deadline.toISOString().split('T')[0].replace(/-/g, '.'),
dDay: dDay,
progressRate: task.progressRate // 서비스에서 계산된 값 사용
};
});
return {
taskId: task.id,
folderId: task.folderId,
folderTitle: task.folder?.title || "PENDING",
title: task.title,
type: task.type === "TEAM" ? "TEAM" : "INDIVIDUAL",
deadline: task.deadline.toISOString().split('T')[0].replace(/-/g, '.'),
dDay: dDay,
progressRate: task.progressRate // 서비스에서 계산된 값 사용
};
});
};

export const responseFromCompletedTasks = (tasks) => {
Expand All @@ -100,11 +100,11 @@ export const responseFromCompletedTasks = (tasks) => {
taskId: task.id,
title: task.title,
deadline: task.deadline ? new Date(task.deadline).toISOString().split('T')[0] : null,
type: task.type === "TEAM" ? "팀" : "개인",

type: task.type === "TEAM" ? "팀" : "개인",

status: task.status === 'COMPLETED' ? '완료' : task.status,

folderId: task.folder ? task.folder.id : null,
folderTitle: task.folder ? task.folder.folderTitle : null,
color: task.folder ? task.folder.color : null,
Expand Down
Loading