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:
Ken Yasue
2026-06-25 10:51:50 +02:00
parent b2b3fb00b5
commit 91dd05ba7b
17 changed files with 885 additions and 76 deletions

View File

@ -76,4 +76,99 @@ test.describe('todo / kanban', () => {
page.getByTestId(`kanban-column-${done.id}`).getByText(title)
).toBeVisible();
});
test('edit dialog shows and persists metadata + file attachments', async ({
page,
}) => {
const projectId = await setupOwner(page);
const colsRes = await page.request.get(
`/api/projects/${projectId}/todos/columns`
);
const cols = (
(await colsRes.json()) as { columns: { id: number; name: string }[] }
).columns;
const backlog = cols.find((c) => c.name === 'Backlog')!;
// オーナー(担当者候補)のuser idを取得
const members = (
(await (
await page.request.get(`/api/projects/${projectId}/members`)
).json()) as { members: { user: { id: number; name: string } }[] }
).members;
const ownerId = members[0].user.id;
// タスク作成(API)
const title = unique('Task');
const createRes = await page.request.post(
`/api/projects/${projectId}/todos/items`,
{ data: { title, columnId: backlog.id } }
);
const { item } = (await createRes.json()) as { item: { id: number } };
// 添付ファイル(1x1 PNG)をアップロード
const png = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=',
'base64'
);
const upRes = await page.request.post(
`/api/projects/${projectId}/attachments`,
{
multipart: {
file: { name: 'pic.png', mimeType: 'image/png', buffer: png },
},
}
);
expect(upRes.ok()).toBeTruthy();
const { file } = (await upRes.json()) as { file: { id: number } };
// ダイアログを開いてメタデータを編集
await page.goto(`/projects/${projectId}/todos`);
await page.getByTestId(`todo-card-${item.id}`).click();
await expect(page.getByTestId('todo-dialog')).toBeVisible();
await page.getByTestId('todo-description').fill('detailed desc');
await page.getByTestId('todo-tags').fill('frontend, urgent');
await page.getByTestId('todo-start-date').fill('2026-07-01');
await page.getByTestId('todo-due-date').fill('2026-07-31');
await page.getByTestId('todo-assignee').selectOption(String(ownerId));
await page.getByTestId('todo-save').click();
await expect(page.getByTestId('todo-dialog')).toBeHidden();
// カードにタグが表示される
await expect(page.getByText('frontend')).toBeVisible();
// APIでファイルを添付付け
const attachRes = await page.request.patch(
`/api/projects/${projectId}/todos/items/${item.id}`,
{ data: { fileIds: [file.id] } }
);
expect(attachRes.ok()).toBeTruthy();
// GET でアイテム+添付が取得できる
const getRes = await page.request.get(
`/api/projects/${projectId}/todos/items/${item.id}`
);
const body = (await getRes.json()) as {
item: {
description: string;
tags: string;
startDate: string;
dueDate: string;
assigneeId: number;
};
attachments: { fileId: number }[];
};
expect(body.item.description).toBe('detailed desc');
expect(body.item.tags).toBe('frontend, urgent');
expect(body.item.startDate).toBe('2026-07-01');
expect(body.item.dueDate).toBe('2026-07-31');
expect(body.item.assigneeId).toBe(ownerId);
expect(body.attachments).toHaveLength(1);
// ダイアログ再オープンで添付画像が表示される
await page.reload();
await page.getByTestId(`todo-card-${item.id}`).click();
await expect(page.getByTestId('todo-dialog')).toBeVisible();
await expect(page.getByTestId('attachment-list')).toBeVisible();
});
});

View File

@ -182,6 +182,7 @@ describe('Migrator', () => {
expect(migrator.getAppliedMigrations().map((m) => m.filename)).toEqual([
'001_initial.sql',
'002_attachments.sql',
'003_todo_tags.sql',
]);
});
});

View File

@ -114,6 +114,49 @@ describe('TodoRepository', () => {
expect(updated?.completedAt).toBeTruthy();
});
it('persists startDate and tags on create', () => {
const item = repo.createItem({
projectId,
columnId,
title: 't',
creatorId: userId,
orderIndex: 0,
startDate: '2026-07-01',
tags: 'frontend,urgent',
});
const found = repo.findItemById(item.id);
expect(found?.startDate).toBe('2026-07-01');
expect(found?.tags).toBe('frontend,urgent');
});
it('updates startDate and tags', () => {
const item = repo.createItem({
projectId,
columnId,
title: 't',
creatorId: userId,
orderIndex: 0,
});
const updated = repo.updateItem(item.id, {
startDate: '2026-08-01',
tags: 'backend',
});
expect(updated?.startDate).toBe('2026-08-01');
expect(updated?.tags).toBe('backend');
});
it('defaults startDate and tags to null when omitted', () => {
const item = repo.createItem({
projectId,
columnId,
title: 't',
creatorId: userId,
orderIndex: 0,
});
expect(item.startDate).toBeNull();
expect(item.tags).toBeNull();
});
it('isolates items by project', () => {
const p2 = new ProjectRepository(db).create({
name: 'P2',

View File

@ -5,10 +5,13 @@ import { UserRepository } from '@/repositories/UserRepository';
import { ProjectRepository } from '@/repositories/ProjectRepository';
import { ProjectMemberRepository } from '@/repositories/ProjectMemberRepository';
import { TodoRepository } from '@/repositories/TodoRepository';
import { FileRepository } from '@/repositories/FileRepository';
import { AttachmentRepository } from '@/repositories/AttachmentRepository';
import { NotificationRepository } from '@/repositories/NotificationRepository';
import { ActivityLogRepository } from '@/repositories/ActivityLogRepository';
import { NotificationService } from '@/services/NotificationService';
import { ActivityLogService } from '@/services/ActivityLogService';
import { AttachmentService } from '@/services/AttachmentService';
import { TodoService } from '@/services/TodoService';
import { SseHub } from '@/lib/sse/hub';
import { ForbiddenError, NotFoundError } from '@/lib/errors';
@ -24,7 +27,13 @@ function makeService(db: SqliteDatabase) {
members,
new NotificationService(new NotificationRepository(db)),
new ActivityLogService(new ActivityLogRepository(db)),
hub
hub,
new AttachmentService(
new AttachmentRepository(db),
new FileRepository(db),
members
),
db
),
members,
users,
@ -161,4 +170,142 @@ describe('TodoService', () => {
NotFoundError
);
});
it('createItem persists startDate/tags and attaches files', () => {
const col = service.getColumns(authorId, projectId)[0];
const fileRepo = new FileRepository(db);
const f1 = fileRepo.create({
projectId,
uploaderId: authorId,
filename: 'a.png',
originalName: 'a.png',
mimeType: 'image/png',
size: 1,
path: '/tmp/a.png',
source: 'attachment',
});
const item = service.createItem(authorId, projectId, {
title: 'rich',
columnId: col.id,
startDate: '2026-07-01',
dueDate: '2026-07-31',
tags: 'frontend,urgent',
fileIds: [f1.id],
});
expect(item.startDate).toBe('2026-07-01');
expect(item.tags).toBe('frontend,urgent');
expect(service.getItemAttachments(authorId, item.id)).toHaveLength(1);
});
it('updateItem updates startDate/tags and attaches new files', () => {
const col = service.getColumns(authorId, projectId)[0];
const item = service.createItem(authorId, projectId, {
title: 't',
columnId: col.id,
});
const fileRepo = new FileRepository(db);
const f1 = fileRepo.create({
projectId,
uploaderId: authorId,
filename: 'b.png',
originalName: 'b.png',
mimeType: 'image/png',
size: 1,
path: '/tmp/b.png',
source: 'attachment',
});
const updated = service.updateItem(authorId, item.id, {
description: 'desc',
startDate: '2026-08-01',
tags: 'backend',
fileIds: [f1.id],
});
expect(updated.description).toBe('desc');
expect(updated.startDate).toBe('2026-08-01');
expect(updated.tags).toBe('backend');
expect(service.getItemAttachments(authorId, item.id)).toHaveLength(1);
});
it('deleteItem detaches its attachments', () => {
const col = service.getColumns(authorId, projectId)[0];
const fileRepo = new FileRepository(db);
const f1 = fileRepo.create({
projectId,
uploaderId: authorId,
filename: 'a.png',
originalName: 'a.png',
mimeType: 'image/png',
size: 1,
path: '/tmp/a.png',
source: 'attachment',
});
const item = service.createItem(authorId, projectId, {
title: 't',
columnId: col.id,
fileIds: [f1.id],
});
expect(service.getItemAttachments(authorId, item.id)).toHaveLength(1);
service.deleteItem(authorId, item.id);
expect(
new AttachmentRepository(db).findByTarget('todo_item', item.id)
).toHaveLength(0);
});
it('getItem and getItemAttachments enforce membership', () => {
const col = service.getColumns(authorId, projectId)[0];
const item = service.createItem(authorId, projectId, {
title: 't',
columnId: col.id,
});
expect(service.getItem(authorId, item.id).id).toBe(item.id);
expect(() => service.getItem(outsiderId, item.id)).toThrow(ForbiddenError);
expect(() => service.getItemAttachments(outsiderId, item.id)).toThrow(
ForbiddenError
);
});
it('only the creator or an admin can delete an item (member-but-not-creator cannot)', () => {
const col = service.getColumns(authorId, projectId)[0];
// authorId(admin)が作成したアイテムを memberId(非管理者・非作成者)は削除できない
const item = service.createItem(authorId, projectId, {
title: 't',
columnId: col.id,
});
expect(() => service.deleteItem(memberId, item.id)).toThrow(ForbiddenError);
// admin(作成者)は削除可
service.deleteItem(authorId, item.id);
expect(() => service.getItem(authorId, item.id)).toThrow(NotFoundError);
});
it('deleteColumn: admin can delete, non-admin member cannot', () => {
const col = service.getColumns(authorId, projectId)[0];
// memberId(非管理者)はカラム削除不可
expect(() => service.deleteColumn(memberId, col.id)).toThrow(
ForbiddenError
);
// authorId(admin)は削除可
service.deleteColumn(authorId, col.id);
expect(() => service.updateColumn(authorId, col.id, { name: 'x' })).toThrow(
NotFoundError
);
});
it('clears startDate/tags/assigneeId via null on update', () => {
const col = service.getColumns(authorId, projectId)[0];
const item = service.createItem(authorId, projectId, {
title: 't',
columnId: col.id,
startDate: '2026-07-01',
tags: 'a,b',
assigneeId: memberId,
});
const cleared = service.updateItem(authorId, item.id, {
startDate: null,
tags: null,
assigneeId: null,
});
expect(cleared.startDate).toBeNull();
expect(cleared.tags).toBeNull();
expect(cleared.assigneeId).toBeNull();
});
});