| 34 | }, |
| 35 | |
| 36 | async update( |
| 37 | id: string, |
| 38 | data: { text?: string; completed?: boolean }, |
| 39 | ): Promise<Todo | null> { |
| 40 | const response = await fetch(`${BASE_URL}/api/todos/${id}`, { |
| 41 | method: 'PUT', |
| 42 | headers: { 'Content-Type': 'application/json' }, |
| 43 | body: JSON.stringify(data), |
| 44 | }) |
| 45 | if (response.status === 404) return null |
| 46 | if (!response.ok) { |
| 47 | throw new Error(`Failed to update todo: ${response.status}`) |
| 48 | } |
| 49 | return response.json() |
| 50 | }, |
| 51 | |
| 52 | async delete(id: string): Promise<boolean> { |
| 53 | const response = await fetch(`${BASE_URL}/api/todos/${id}`, { |