(input: {
id?: string;
name: string;
sortOrder?: number;
})
| 29 | } |
| 30 | |
| 31 | export async function insertGroup(input: { |
| 32 | id?: string; |
| 33 | name: string; |
| 34 | sortOrder?: number; |
| 35 | }): Promise<BookGroup> { |
| 36 | const database = await getDB(); |
| 37 | const deviceId = await getDeviceId(); |
| 38 | const syncVersion = await nextSyncVersion(database, "book_groups"); |
| 39 | const now = Date.now(); |
| 40 | const group: BookGroup = { |
| 41 | id: input.id ?? generateId(), |
| 42 | name: input.name.trim(), |
| 43 | sortOrder: input.sortOrder ?? now, |
| 44 | createdAt: now, |
| 45 | updatedAt: now, |
| 46 | }; |
| 47 | |
| 48 | await database.execute( |
| 49 | `INSERT INTO book_groups (id, name, sort_order, created_at, updated_at, sync_version, last_modified_by) |
| 50 | VALUES (?, ?, ?, ?, ?, ?, ?)`, |
| 51 | [ |
| 52 | group.id, |
| 53 | group.name, |
| 54 | group.sortOrder, |
| 55 | group.createdAt, |
| 56 | group.updatedAt, |
| 57 | syncVersion, |
| 58 | deviceId, |
| 59 | ], |
| 60 | ); |
| 61 | |
| 62 | return group; |
| 63 | } |
| 64 | |
| 65 | export async function updateGroup( |
| 66 | id: string, |
no test coverage detected