MCPcopy Create free account
hub / github.com/disler/claude-code-hooks-mastery / TaskRepository

Class TaskRepository

apps/task-manager/src/db/repository.ts:49–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47 * Task Repository class for database operations
48 */
49export class TaskRepository {
50 private db: Database;
51
52 constructor() {
53 this.db = getDatabase();
54 }
55
56 /**
57 * Create a new task
58 * @param input - Task creation input
59 * @returns The created task
60 */
61 create(input: CreateTaskInput): Task {
62 const now = new Date().toISOString();
63
64 try {
65 const stmt = this.db.prepare(`
66 INSERT INTO tasks (title, description, priority, due_date, completed, created_at)
67 VALUES (?, ?, ?, ?, 0, ?)
68 `);
69
70 const result = stmt.run(
71 input.title,
72 input.description ?? null,
73 input.priority,
74 input.dueDate ?? null,
75 now
76 );
77
78 const id = Number(result.lastInsertRowid);
79
80 // Fetch and return the created task
81 const task = this.findById(id);
82 if (!task) {
83 throw new Error('Failed to retrieve created task');
84 }
85
86 return task;
87 } catch (error) {
88 const message = error instanceof Error ? error.message : 'Unknown error';
89 throw new Error(`Failed to create task: ${message}`);
90 }
91 }
92
93 /**
94 * Find all tasks with optional filters
95 * @param filters - Optional filters for priority, completed status, pending, overdue
96 * @returns Array of tasks matching the filters
97 */
98 findAll(filters?: {
99 priority?: Priority;
100 completed?: boolean;
101 pending?: boolean;
102 overdue?: boolean;
103 }): Task[] {
104 try {
105 let query = 'SELECT * FROM tasks WHERE 1=1';
106 const params: (string | number)[] = [];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected