Skip to content

Commit

Permalink
Error handling update
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
JohanGrims and coderabbitai[bot] authored Dec 7, 2024
1 parent 4966940 commit 254969c
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/admin/vote/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,43 @@ export default function Edit() {
}

async function update() {
console.log("Publishing vote with id: " + vote.id);

const updatedVote = await setDoc(
doc(db, "/votes", vote.id),
{
title,
description: description || "",
},
{ merge: true }
);
const optionsPromises = options.map(async (e) => {
return setDoc(doc(db, `/votes/${vote.id}/options/${e.id}`), {
title: e.title,
max: e.max,
teacher: e.teacher,
description: e.description,
try {
console.log("Publishing vote with id: " + vote.id);

await setDoc(
doc(db, "/votes", vote.id),
{
title,
description: description || "",
},
{ merge: true }
);
const optionsPromises = options.map(async (e) => {
return setDoc(doc(db, `/votes/${vote.id}/options/${e.id}`), {
title: e.title,
max: e.max,
teacher: e.teacher,
description: e.description,
});
});
});

await Promise.all(optionsPromises);
await Promise.all(optionsPromises);

console.log("Vote created successfully.");
console.log("Vote created successfully.");

snackbar({
message: "Wahl erfolgreich erstellt.",
timeout: 5000,
});
snackbar({
message: "Wahl erfolgreich erstellt.",
timeout: 5000,
});

navigate(`/admin/${vote.id}`);
navigate(`/admin/${vote.id}`);
} catch (error) {
console.error("Failed to update vote:", error);
snackbar({
message: "Fehler beim Aktualisieren der Wahl.",
timeout: 5000,
});
}
}

const isVoteUnchanged = () => {
Expand Down

0 comments on commit 254969c

Please sign in to comment.