Add PUT route to update existing adventure and refactor adventureService

This commit is contained in:
Sean Morley
2024-04-10 14:58:42 +00:00
parent ed9a579fc2
commit 45545fd8ce
3 changed files with 74 additions and 43 deletions

View File

@@ -31,28 +31,6 @@ export function getAdventures(): Adventure[] {
return adventures;
}
export function saveEdit(adventure: Adventure) {
let editId = adventure.id;
console.log("saving edit");
let editName = adventure.name;
let editLocation = adventure.location;
let editCreated = adventure.created;
let oldAdventure: Adventure | undefined = adventures.find(
(adventure) => adventure.id === editId
);
console.log("old" + oldAdventure);
if (oldAdventure) {
oldAdventure.name = editName;
oldAdventure.location = editLocation;
oldAdventure.created = editCreated;
}
editId = NaN;
console.log("done");
if (isBrowser) {
localStorage.setItem("adventures", JSON.stringify(adventures));
}
}
export function clearAdventures() {
adventures = [];
if (isBrowser) {