feat(todo): richer metadata (tags, startDate, files) + edit/detail dialog
ToDoアイテムのメタデータを拡充し、編集/詳細ダイアログを追加。
- lib/db/migrations/003_todo_tags.sql: todo_items に tags 列を追加
- TodoRepository/TodoService: startDate(従来ハードコードNULL)とtagsをcreate/updateで永続化、fileIdsで添付紐付け(トランザクション)、deleteItemで添付クリーンアップ、getItem/getItemAttachments を追加
- API: GET /todos/items/[itemId] ({item, attachments}) を追加、POST/PATCH で startDate/tags/fileIds を受理、PATCH は null(クリア)と undefined(更新しない)を区別
- UI: TodoDialog(タイトル/説明/担当/優先度/開始日/期限/タグ/添付を編集、完了日時・タイムスタンプは読み取り専用)、KanbanBoard のカードクリックでダイアログを開きメタデータを表示
- MilestoneRepository の todo マッピングに tags を追加し as never キャストを修正
- docs/functional-design.md に tags / file_assets.source / attachments テーブルを追記
This commit is contained in:
@ -6,6 +6,23 @@ import { handleApiError, jsonError } from '@/lib/api/handleError';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string; itemId: string }> }
|
||||
) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) return handleApiError(new UnauthorizedError());
|
||||
const { itemId } = await params;
|
||||
const service = createTodoService();
|
||||
try {
|
||||
const item = service.getItem(user.id, Number(itemId));
|
||||
const attachments = service.getItemAttachments(user.id, Number(itemId));
|
||||
return NextResponse.json({ item, attachments });
|
||||
} catch (error) {
|
||||
return handleApiError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string; itemId: string }> }
|
||||
@ -35,23 +52,29 @@ export async function PATCH(
|
||||
);
|
||||
return NextResponse.json({ item });
|
||||
}
|
||||
// nullable フィールドは absent(undefined=更新しない) と null(クリア) を区別する
|
||||
const nullableString = (v: unknown): string | null | undefined =>
|
||||
v === undefined ? undefined : v === null ? null : String(v);
|
||||
const nullableNumber = (v: unknown): number | null | undefined =>
|
||||
v === undefined ? undefined : v === null ? null : Number(v);
|
||||
|
||||
const item = service.updateItem(user.id, Number(itemId), {
|
||||
title: typeof body.title === 'string' ? body.title : undefined,
|
||||
description:
|
||||
typeof body.description === 'string' ? body.description : undefined,
|
||||
assigneeId:
|
||||
body.assigneeId === null || body.assigneeId === undefined
|
||||
? undefined
|
||||
: Number(body.assigneeId),
|
||||
description: nullableString(body.description),
|
||||
assigneeId: nullableNumber(body.assigneeId),
|
||||
priority:
|
||||
typeof body.priority === 'string'
|
||||
? (body.priority as 'low' | 'normal' | 'high')
|
||||
: undefined,
|
||||
dueDate: typeof body.dueDate === 'string' ? body.dueDate : undefined,
|
||||
milestoneId:
|
||||
body.milestoneId === null || body.milestoneId === undefined
|
||||
? undefined
|
||||
: Number(body.milestoneId),
|
||||
startDate: nullableString(body.startDate),
|
||||
dueDate: nullableString(body.dueDate),
|
||||
tags: nullableString(body.tags),
|
||||
milestoneId: nullableNumber(body.milestoneId),
|
||||
fileIds: Array.isArray(body.fileIds)
|
||||
? body.fileIds
|
||||
.map((n) => Number(n))
|
||||
.filter((n) => Number.isFinite(n) && n > 0)
|
||||
: undefined,
|
||||
});
|
||||
return NextResponse.json({ item });
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user