diff --git a/frontend/src/Utils/convertToNMP.ts b/frontend/src/Utils/convertToNMP.ts index 7603e22e..5620ce25 100644 --- a/frontend/src/Utils/convertToNMP.ts +++ b/frontend/src/Utils/convertToNMP.ts @@ -70,12 +70,10 @@ const convertToNMP = ( sampleDate: field.SoilTest.sampleDate ?? '2024-07-01T00:00:00', } : null, - LeafTest: field.HasLeafTest - ? { - leafTissueP: field.LeafTest.leafTissueP, - leafTissueK: field.LeafTest.leafTissueK, - } - : null, + LeafTest: { + leafTissueP: field.LeafTest?.leafTissueP ?? 0, + leafTissueK: field.LeafTest?.leafTissueK ?? 0, + }, Crops: newCrops, HasNutrients: field.Nutrients && field.Nutrients?.nutrientFertilizers?.length >= 0, diff --git a/frontend/src/Utils/getLocalDetails.ts b/frontend/src/Utils/getLocalDetails.ts index 870bb4ee..a8f61ca2 100644 --- a/frontend/src/Utils/getLocalDetails.ts +++ b/frontend/src/Utils/getLocalDetails.ts @@ -31,7 +31,11 @@ const loadFarmDetails = (): FarmDetailsInterface => { updatedFarmDetails.FarmRegion = nmpFarmDetails.FarmRegion ?? 0; fieldsJSON.forEach((field) => { - const updateField: FieldDetailInterface = field; + const updateField: FieldDetailInterface = { + ...field, + HasLeafTest: + (field.LeafTest?.leafTissueK >= 0 && field.LeafTest?.leafTissueP >= 0) ?? false, + }; updatedFarmDetails.Fields.push(updateField); }); updatedFarmDetails.Fields = localDetails.years[0].Fields; diff --git a/frontend/src/Utils/getLocalFertilizers.ts b/frontend/src/Utils/getLocalFertilizers.ts index 5c57296d..c4e2a487 100644 --- a/frontend/src/Utils/getLocalFertilizers.ts +++ b/frontend/src/Utils/getLocalFertilizers.ts @@ -21,8 +21,8 @@ const loadFertDetails = (farmDetails: FarmDetailsInterface): FertilizerInterface const localFerts = getLocalFertilizers(); const updatedFertDetails = [...localFerts]; - farmDetails.Fields.forEach((field) => { - field.Nutrients.nutrientFertilizers.forEach((fertilizer) => { + farmDetails.Fields?.forEach((field) => { + field.Nutrients.nutrientFertilizers?.forEach((fertilizer) => { const normalizedFertilizerId = fertilizer.fertilizerId.toString(); if (!updatedFertDetails.find((f) => f.fertilizerId === normalizedFertilizerId)) {