배포용 수정
This commit is contained in:
@@ -61,13 +61,20 @@ export class TodoService {
|
||||
* 데이터 디렉토리 생성 (파일 모드)
|
||||
*/
|
||||
private ensureDataDirectory(): void {
|
||||
if (!fs.existsSync(TODO_DIR)) {
|
||||
fs.mkdirSync(TODO_DIR, { recursive: true });
|
||||
logger.info(`📁 To-Do 데이터 디렉토리 생성: ${TODO_DIR}`);
|
||||
}
|
||||
if (!fs.existsSync(TODO_FILE)) {
|
||||
fs.writeFileSync(TODO_FILE, JSON.stringify([], null, 2));
|
||||
logger.info(`📄 To-Do 파일 생성: ${TODO_FILE}`);
|
||||
try {
|
||||
if (!fs.existsSync(TODO_DIR)) {
|
||||
fs.mkdirSync(TODO_DIR, { recursive: true, mode: 0o755 });
|
||||
logger.info(`📁 To-Do 데이터 디렉토리 생성: ${TODO_DIR}`);
|
||||
}
|
||||
if (!fs.existsSync(TODO_FILE)) {
|
||||
fs.writeFileSync(TODO_FILE, JSON.stringify([], null, 2), {
|
||||
mode: 0o644,
|
||||
});
|
||||
logger.info(`📄 To-Do 파일 생성: ${TODO_FILE}`);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`❌ To-Do 디렉토리 생성 실패: ${TODO_DIR}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,15 +87,17 @@ export class TodoService {
|
||||
assignedTo?: string;
|
||||
}): Promise<TodoListResponse> {
|
||||
try {
|
||||
const todos = DATA_SOURCE === "database"
|
||||
? await this.loadTodosFromDB(filter)
|
||||
: this.loadTodosFromFile(filter);
|
||||
const todos =
|
||||
DATA_SOURCE === "database"
|
||||
? await this.loadTodosFromDB(filter)
|
||||
: this.loadTodosFromFile(filter);
|
||||
|
||||
// 정렬: 긴급 > 우선순위 > 순서
|
||||
todos.sort((a, b) => {
|
||||
if (a.isUrgent !== b.isUrgent) return a.isUrgent ? -1 : 1;
|
||||
const priorityOrder = { urgent: 0, high: 1, normal: 2, low: 3 };
|
||||
if (a.priority !== b.priority) return priorityOrder[a.priority] - priorityOrder[b.priority];
|
||||
if (a.priority !== b.priority)
|
||||
return priorityOrder[a.priority] - priorityOrder[b.priority];
|
||||
return a.order - b.order;
|
||||
});
|
||||
|
||||
@@ -124,7 +133,8 @@ export class TodoService {
|
||||
await this.createTodoDB(newTodo);
|
||||
} else {
|
||||
const todos = this.loadTodosFromFile();
|
||||
newTodo.order = todos.length > 0 ? Math.max(...todos.map((t) => t.order)) + 1 : 0;
|
||||
newTodo.order =
|
||||
todos.length > 0 ? Math.max(...todos.map((t) => t.order)) + 1 : 0;
|
||||
todos.push(newTodo);
|
||||
this.saveTodosToFile(todos);
|
||||
}
|
||||
@@ -140,7 +150,10 @@ export class TodoService {
|
||||
/**
|
||||
* To-Do 항목 수정
|
||||
*/
|
||||
public async updateTodo(id: string, updates: Partial<TodoItem>): Promise<TodoItem> {
|
||||
public async updateTodo(
|
||||
id: string,
|
||||
updates: Partial<TodoItem>
|
||||
): Promise<TodoItem> {
|
||||
try {
|
||||
if (DATA_SOURCE === "database") {
|
||||
return await this.updateTodoDB(id, updates);
|
||||
@@ -231,7 +244,9 @@ export class TodoService {
|
||||
dueDate: row.dueDate ? new Date(row.dueDate).toISOString() : undefined,
|
||||
createdAt: new Date(row.createdAt).toISOString(),
|
||||
updatedAt: new Date(row.updatedAt).toISOString(),
|
||||
completedAt: row.completedAt ? new Date(row.completedAt).toISOString() : undefined,
|
||||
completedAt: row.completedAt
|
||||
? new Date(row.completedAt).toISOString()
|
||||
: undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -263,7 +278,10 @@ export class TodoService {
|
||||
);
|
||||
}
|
||||
|
||||
private async updateTodoDB(id: string, updates: Partial<TodoItem>): Promise<TodoItem> {
|
||||
private async updateTodoDB(
|
||||
id: string,
|
||||
updates: Partial<TodoItem>
|
||||
): Promise<TodoItem> {
|
||||
const setClauses: string[] = ["updated_at = NOW()"];
|
||||
const params: any[] = [];
|
||||
let paramIndex = 1;
|
||||
@@ -327,12 +345,17 @@ export class TodoService {
|
||||
dueDate: row.dueDate ? new Date(row.dueDate).toISOString() : undefined,
|
||||
createdAt: new Date(row.createdAt).toISOString(),
|
||||
updatedAt: new Date(row.updatedAt).toISOString(),
|
||||
completedAt: row.completedAt ? new Date(row.completedAt).toISOString() : undefined,
|
||||
completedAt: row.completedAt
|
||||
? new Date(row.completedAt).toISOString()
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
private async deleteTodoDB(id: string): Promise<void> {
|
||||
const rows = await query("DELETE FROM todo_items WHERE id = $1 RETURNING id", [id]);
|
||||
const rows = await query(
|
||||
"DELETE FROM todo_items WHERE id = $1 RETURNING id",
|
||||
[id]
|
||||
);
|
||||
if (rows.length === 0) {
|
||||
throw new Error(`To-Do 항목을 찾을 수 없습니다: ${id}`);
|
||||
}
|
||||
@@ -443,7 +466,10 @@ export class TodoService {
|
||||
inProgress: todos.filter((t) => t.status === "in_progress").length,
|
||||
completed: todos.filter((t) => t.status === "completed").length,
|
||||
urgent: todos.filter((t) => t.isUrgent).length,
|
||||
overdue: todos.filter((t) => t.dueDate && new Date(t.dueDate) < now && t.status !== "completed").length,
|
||||
overdue: todos.filter(
|
||||
(t) =>
|
||||
t.dueDate && new Date(t.dueDate) < now && t.status !== "completed"
|
||||
).length,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user