| 64 | }, |
| 65 | |
| 66 | async update( |
| 67 | id: string, |
| 68 | data: { text?: string; completed?: boolean }, |
| 69 | ): Promise<Todo | null> { |
| 70 | const response = await fetch(`${BASE_URL}/api/todos/${id}`, { |
| 71 | method: 'PUT', |
| 72 | headers: { 'Content-Type': 'application/json' }, |
| 73 | body: JSON.stringify(data), |
| 74 | }) |
| 75 | if (response.status === 404) { |
| 76 | return null |
| 77 | } |
| 78 | if (!response.ok) { |
| 79 | throw new Error(`Failed to update todo: ${response.status}`) |
| 80 | } |
| 81 | const todo: TodoResponse = await response.json() |
| 82 | return parseTodo(todo) |
| 83 | }, |
| 84 | |
| 85 | async delete(id: string): Promise<boolean> { |
| 86 | const response = await fetch(`${BASE_URL}/api/todos/${id}`, { |