(id: string, updates: Partial<Note>)
| 92 | } |
| 93 | |
| 94 | export async function updateNote(id: string, updates: Partial<Note>): Promise<void> { |
| 95 | const database = await getDB(); |
| 96 | const sets: string[] = []; |
| 97 | const values: unknown[] = []; |
| 98 | |
| 99 | if (updates.title !== undefined) { |
| 100 | sets.push("title = ?"); |
| 101 | values.push(updates.title); |
| 102 | } |
| 103 | if (updates.content !== undefined) { |
| 104 | sets.push("content = ?"); |
| 105 | values.push(updates.content); |
| 106 | } |
| 107 | if (updates.tags !== undefined) { |
| 108 | sets.push("tags = ?"); |
| 109 | values.push(JSON.stringify(updates.tags)); |
| 110 | } |
| 111 | // Add sync tracking |
| 112 | const deviceId = await getDeviceId(); |
| 113 | const syncVersion = await nextSyncVersion(database, "notes"); |
| 114 | const updatedAt = await nextUpdatedAt(database, "notes", id); |
| 115 | sets.push("updated_at = ?"); |
| 116 | values.push(updatedAt); |
| 117 | sets.push("sync_version = ?"); |
| 118 | values.push(syncVersion); |
| 119 | sets.push("last_modified_by = ?"); |
| 120 | values.push(deviceId); |
| 121 | |
| 122 | if (sets.length === 0) return; |
| 123 | values.push(id); |
| 124 | await database.execute(`UPDATE notes SET ${sets.join(", ")} WHERE id = ?`, values); |
| 125 | } |
| 126 | |
| 127 | export async function deleteNote(id: string): Promise<void> { |
| 128 | const database = await getDB(); |
no test coverage detected