feat: add remote pull and push
This commit is contained in:
@@ -87,6 +87,7 @@ class DriftBarTabService implements BarTabService {
|
||||
status: row.status,
|
||||
openedAt: row.openedAt,
|
||||
closedAt: row.closedAt,
|
||||
version: row.version,
|
||||
items: items,
|
||||
);
|
||||
}
|
||||
@@ -292,6 +293,7 @@ class DriftBarTabService implements BarTabService {
|
||||
@override
|
||||
Future<BarTab> createTab({required String customerName}) async {
|
||||
final id = _uuid.v4();
|
||||
final now = DateTime.now();
|
||||
|
||||
await database
|
||||
.into(database.barTabs)
|
||||
@@ -300,7 +302,8 @@ class DriftBarTabService implements BarTabService {
|
||||
id: id,
|
||||
customerName: customerName,
|
||||
status: const Value('open'),
|
||||
openedAt: DateTime.now(),
|
||||
openedAt: now,
|
||||
version: const Value(1),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -335,6 +338,8 @@ class DriftBarTabService implements BarTabService {
|
||||
if (updatedRows != 1) {
|
||||
throw StateError('Tab not found.');
|
||||
}
|
||||
|
||||
await _incrementTabVersion(tabId);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -368,6 +373,14 @@ class DriftBarTabService implements BarTabService {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _incrementTabVersion(String tabId) async {
|
||||
await database.customUpdate(
|
||||
'UPDATE bar_tabs SET version = version + 1 WHERE id = ?',
|
||||
variables: [Variable.withString(tabId)],
|
||||
updates: {database.barTabs},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addProductToTab({
|
||||
required String tabId,
|
||||
@@ -414,6 +427,8 @@ class DriftBarTabService implements BarTabService {
|
||||
|
||||
await _recordPurchase(tabItemId: tabItemId);
|
||||
});
|
||||
|
||||
await _incrementTabVersion(tabId);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -421,7 +436,9 @@ class DriftBarTabService implements BarTabService {
|
||||
required String tabItemId,
|
||||
required int delta,
|
||||
}) async {
|
||||
return database.transaction(() async {
|
||||
String? tabId;
|
||||
|
||||
final actualDelta = await database.transaction(() async {
|
||||
final item = await (database.select(
|
||||
database.tabItems,
|
||||
)..where((row) => row.id.equals(tabItemId))).getSingleOrNull();
|
||||
@@ -430,6 +447,8 @@ class DriftBarTabService implements BarTabService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tabId = item.tabId;
|
||||
|
||||
final requestedQuantity = item.quantity + delta;
|
||||
final actualDelta = requestedQuantity <= 0 ? -item.quantity : delta;
|
||||
|
||||
@@ -483,6 +502,12 @@ class DriftBarTabService implements BarTabService {
|
||||
|
||||
return actualDelta;
|
||||
});
|
||||
|
||||
if (tabId != null && actualDelta != 0) {
|
||||
await _incrementTabVersion(tabId!);
|
||||
}
|
||||
|
||||
return actualDelta;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -544,6 +569,8 @@ class DriftBarTabService implements BarTabService {
|
||||
|
||||
await deleteQuery.go();
|
||||
});
|
||||
|
||||
await _incrementTabVersion(tabId);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user