Skip to content

Commit 91dc822

Browse files
committed
feat(shopinbit): backfill remote tickets into the local db on refresh
1 parent e7073cb commit 91dc822

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

lib/services/shopinbit/shopinbit_orders_service.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,27 @@ class ShopInBitOrdersService extends ChangeNotifier {
158158
Future<void> refreshAll() async {
159159
try {
160160
final customerKey = await shopInBitService.ensureCustomerKey();
161+
final db = SharedDrift.get();
162+
163+
// Backfill rows for tickets that exist on the API but not locally
164+
// (created on another device, web dashboard, etc.). A failure here
165+
// shouldn't stop the refresh of tickets we already know about.
166+
try {
167+
final newCompanions = await shopInBitService.fetchAllForCustomerKey(
168+
customerKey,
169+
);
170+
for (final companion in newCompanions) {
171+
await db.into(db.shopInBitTickets).insertOnConflictUpdate(companion);
172+
}
173+
} catch (_) {
174+
// Fall through to the refresh-existing path.
175+
}
176+
161177
final resp = await shopInBitService.client.getTicketsByCustomer(
162178
customerKey,
163179
);
164180
if (resp.hasError || resp.value == null) return;
165181

166-
final db = SharedDrift.get();
167182
final localRows = await db.select(db.shopInBitTickets).get();
168183
final byApiId = {for (final r in localRows) r.apiTicketId: r};
169184

0 commit comments

Comments
 (0)