Created
April 30, 2024 18:10
-
-
Save MonteLogic/a0a703e360439b676884fdc5f3cbe227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const updateSummary = async ( | |
entryID: string, | |
date: string, | |
routeID: string, | |
setSummaryObject: React.Dispatch<React.SetStateAction<any>>, | |
summaryObject: any, | |
) => { | |
alert('8, updateSummary'); | |
// I'm pretty sure that BS id creation is coming from here: | |
try { | |
const response = await fetch('/api/search-shift', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify({ entryID, summaryObject }), | |
}); | |
if (response.ok) { | |
const data = await response.json(); | |
const fullSummaryResponse = data?.field?.[0]?.summary || []; | |
if (fullSummaryResponse) { | |
// Update only the relevant parts of the summaryObject | |
const updatedSummaryObject = { | |
...summaryObject, | |
...fullSummaryResponse, | |
}; | |
setSummaryObject(updatedSummaryObject); | |
} else { | |
console.error('No route summary found'); | |
} | |
return 'Has updated'; | |
} else { | |
setSummaryObject('else Error getting work time'); | |
console.error('Error updating work time'); | |
} | |
} catch (error) { | |
setSummaryObject('catch Error getting work time'); | |
console.error('Error updating work time', error); | |
} | |
}; | |
export const createRecordForSummary = async ( | |
dateSelection: string, | |
routeID: string, | |
setSummaryObject: React.Dispatch<React.SetStateAction<any>>, | |
summaryObject: any, | |
) => { | |
// I'm pretty sure that BS id creation is coming from here: | |
console.log(51, dateSelection, routeID, summaryObject); | |
try { | |
// Add dateSelection and routeID to the summaryObject | |
const response = await fetch('/api/search-shift', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify({ | |
dateSelection, | |
routeID, | |
summaryObject, | |
}), | |
}); | |
if (response.ok) { | |
const data = await response.json(); | |
const fullSummaryResponse = data?.field?.[0]?.summary || []; | |
if (fullSummaryResponse) { | |
// Update only the relevant parts of the summaryObject | |
const updatedSummaryObject = { | |
...summaryObject, | |
...fullSummaryResponse, | |
}; | |
setSummaryObject(updatedSummaryObject); | |
} else { | |
console.error('No route summary found'); | |
} | |
return 'Has updated'; | |
} else { | |
setSummaryObject('else Error getting work time'); | |
console.error('Error updating work time'); | |
} | |
} catch (error) { | |
setSummaryObject('catch Error getting work time'); | |
console.error('Error updating work time', error); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment