Files
opengroupware/lib/api/services.ts
Ken Yasue 3e02feb221 feat(m5): notifications & activity log foundation
- Expand NotificationRepository (unread list paginated, count, markRead
  ownership-scoped); new ActivityLogRepository (create, findByProject
  paginated) with deterministic created_at+id ordering
- NotificationService (notifyOnEvent, resolveTargets for 8 event types,
  injectable SseBroadcaster for M8) + ActivityLogService (logActivity,
  listByProject)
- NotificationEvent/SseEvent/SseBroadcaster types in lib/types
- APIs: GET /api/notifications, POST /api/notifications/:id/read,
  GET /api/projects/:projectId/activity
- Screens: notifications list + MarkReadButton, NotificationBadge in
  Header, project activity page + ProjectNav link
- Unit tests for both repositories and services (28 new)
2026-06-25 01:20:24 +02:00

36 lines
1.4 KiB
TypeScript

import { getDb } from '@/lib/db/sqlite';
import { ProjectRepository } from '@/repositories/ProjectRepository';
import { ProjectMemberRepository } from '@/repositories/ProjectMemberRepository';
import { NotificationRepository } from '@/repositories/NotificationRepository';
import { ActivityLogRepository } from '@/repositories/ActivityLogRepository';
import { UserRepository } from '@/repositories/UserRepository';
import { ProjectService } from '@/services/ProjectService';
import { NotificationService } from '@/services/NotificationService';
import { ActivityLogService } from '@/services/ActivityLogService';
/**
* Route Handler用に各Repository/Serviceを構築するファクトリ。
* 依存はすべて同じgetDb()接続を共有し、トランザクション境界を機能させる。
*/
export function createProjectService(): ProjectService {
const db = getDb();
return new ProjectService(
new ProjectRepository(db),
new ProjectMemberRepository(db),
new NotificationRepository(db),
db
);
}
export function createNotificationService(): NotificationService {
return new NotificationService(new NotificationRepository(getDb()));
}
export function createActivityLogService(): ActivityLogService {
return new ActivityLogService(new ActivityLogRepository(getDb()));
}
export function createUserRepository(): UserRepository {
return new UserRepository(getDb());
}