Moves the list to the private realm and removes all members * * The operation is sync-consistent and will work correctly * whether the todo-list is shared or not while the operation * is performed offline. * * The operation may succeed offline but fail later during sync * if s
()
| 87 | * restore the local data to mirror the server state. |
| 88 | */ |
| 89 | async makePrivate() { |
| 90 | const tiedRealmId = getTiedRealmId(this.id); |
| 91 | const db = this.db; |
| 92 | await db.transaction( |
| 93 | 'rw', |
| 94 | [db.todoLists, db.todoItems, db.members, db.realms], |
| 95 | async () => { |
| 96 | // Move todoItems out of the realm in a sync-consistent operation: |
| 97 | await db.todoItems |
| 98 | .where({ |
| 99 | realmId: tiedRealmId, |
| 100 | todoListId: this.id, |
| 101 | }) |
| 102 | .modify({ |
| 103 | realmId: db.cloud.currentUserId, |
| 104 | owner: db.cloud.currentUserId, |
| 105 | }); |
| 106 | |
| 107 | // Move the todoList back into your private realm: |
| 108 | await db.todoLists.update(this.id, { |
| 109 | realmId: this.db.cloud.currentUserId, |
| 110 | owner: this.db.cloud.currentUserId, |
| 111 | }); |
| 112 | |
| 113 | // Remove all access (Collection.delete() is a sync-consistent operation) |
| 114 | await db.members.where('realmId').equals(tiedRealmId).delete(); |
| 115 | // Delete tied realm |
| 116 | await db.realms.delete(tiedRealmId); |
| 117 | } |
| 118 | ); |
| 119 | } |
| 120 | |
| 121 | /** Share the todo list with a new person. |
| 122 | * |
no test coverage detected