feat: Update category server version handling in createCategory and CategoryDialog
This commit is contained in:
@@ -58,12 +58,20 @@ class NoteRepository {
|
||||
Future<void> createCategory(Category category) async {
|
||||
debugPrint('createCategory called with: ${category.name}');
|
||||
|
||||
final DbCategory? existingCategory = await (
|
||||
_database.select(_database.categories)..where((c) => c.id.equals(category.id))
|
||||
).getSingleOrNull();
|
||||
final int effectiveServerVersion = math.max(
|
||||
category.serverVersion,
|
||||
existingCategory?.serverVersion ?? category.serverVersion,
|
||||
);
|
||||
|
||||
await _database.upsertCategory(
|
||||
CategoriesCompanion.insert(
|
||||
id: category.id,
|
||||
name: category.name,
|
||||
updatedAt: category.updatedAt,
|
||||
serverVersion: const Value(0),
|
||||
serverVersion: Value(effectiveServerVersion),
|
||||
isDeleted: const Value(false),
|
||||
isDirty: const Value(true),
|
||||
colorValue: Value<int?>(category.colorValue),
|
||||
|
||||
Reference in New Issue
Block a user