polscm32 aka Marvout 1 год назад
Родитель
Сommit
dac96ccc01
1 измененных файлов с 7 добавлено и 12 удалено
  1. 7 12
      FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift

+ 7 - 12
FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift

@@ -351,7 +351,7 @@ extension DataTable {
         private func deleteOldEntries(
             _ treatmentObjectID: NSManagedObjectID,
             originalEntry: (
-                entryValues: (date: Date, oldCarbs: Double, oldFat: Double, oldProtein: Double)?,
+                entryValues: (date: Date, carbs: Double, fat: Double, protein: Double)?,
                 entryId: NSManagedObjectID
             ),
             newCarbs _: Decimal,
@@ -359,17 +359,14 @@ extension DataTable {
             newProtein _: Decimal,
             newNote _: String
         ) async {
-            // TODO: cleanup
-            // TODO: maybe pass originalEntry instead of treatmentObjectId down?
-
-            if ((originalEntry.entryValues?.oldCarbs ?? 0) == 0 && (originalEntry.entryValues?.oldFat ?? 0) > 0) ||
-                ((originalEntry.entryValues?.oldCarbs ?? 0) == 0 && (originalEntry.entryValues?.oldProtein ?? 0) > 0)
+            if ((originalEntry.entryValues?.carbs ?? 0) == 0 && (originalEntry.entryValues?.fat ?? 0) > 0) ||
+                ((originalEntry.entryValues?.carbs ?? 0) == 0 && (originalEntry.entryValues?.protein ?? 0) > 0)
             {
                 // Delete the zero-carb-entry and all its carb equivalents connected by the same fpuID from remote services and Core Data
                 // Use fpuID
                 await deleteCarbs(treatmentObjectID, isFpuOrComplexMeal: true)
-            } else if ((originalEntry.entryValues?.oldCarbs ?? 0) > 0 && (originalEntry.entryValues?.oldFat ?? 0) > 0) ||
-                ((originalEntry.entryValues?.oldCarbs ?? 0) > 0 && (originalEntry.entryValues?.oldProtein ?? 0) > 0)
+            } else if ((originalEntry.entryValues?.carbs ?? 0) > 0 && (originalEntry.entryValues?.fat ?? 0) > 0) ||
+                ((originalEntry.entryValues?.carbs ?? 0) > 0 && (originalEntry.entryValues?.protein ?? 0) > 0)
             {
                 // Delete carb entry and carb equivalents that are all connected by the same fpuID from remote services and Core Data
                 // Use fpuID
@@ -386,21 +383,19 @@ extension DataTable {
         /// - Parameter objectID: The ID of the entry
         /// - Returns: A tuple of the old entry values and its original date and the objectID or nil
         private func getOriginalEntryValues(_ objectID: NSManagedObjectID) async
-            -> (entryValues: (date: Date, oldCarbs: Double, oldFat: Double, oldProtein: Double)?, entryId: NSManagedObjectID)?
+            -> (entryValues: (date: Date, carbs: Double, fat: Double, protein: Double)?, entryId: NSManagedObjectID)?
         {
             let context = CoreDataStack.shared.newTaskContext()
             context.name = "updateContext"
             context.transactionAuthor = "updateEntry"
 
-            // TODO: possibly extend this by id and fpuID to not having to fetch again later on
-
             return await context.perform {
                 do {
                     guard let entry = try context.existingObject(with: objectID) as? CarbEntryStored, let entryDate = entry.date
                     else { return nil }
 
                     return (
-                        entryValues: (date: entryDate, oldCarbs: entry.carbs, oldFat: entry.fat, oldProtein: entry.protein),
+                        entryValues: (date: entryDate, carbs: entry.carbs, fat: entry.fat, protein: entry.protein),
                         entryId: entry.objectID
                     )
                 } catch let error as NSError {