Skip to content

Commit

Permalink
MODIFY: actions now return better, succinct error and success messages
Browse files Browse the repository at this point in the history
  • Loading branch information
srkuleo committed Aug 31, 2024
1 parent 31dc380 commit f144a98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/util/actions/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ export async function updateUserTimeFormatPreference(
.set({ preferences: { ...user.preferences, timeFormat: value } })
.where(eq(users.id, user.id));

console.log(`Time format set to - ${value}`);
console.log(`Time format - ${value}`);

revalidatePath("/profile");

return {
status: "success",
message: `Time format set to - ${value}`,
message: `Time format - ${value}`,
};
} catch (error) {
console.log(error);

return {
status: "error",
message: "Database Error: Time format could not be changed",
message: "Failed to set new time format...",
};
}
}
28 changes: 14 additions & 14 deletions src/util/actions/workout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function createWorkout(
return {
status: "error",
errors: isValidWorkout.error.flatten().fieldErrors,
message: "Workout could not be created",
message: "Invalid workout data",
};
}

Expand All @@ -50,7 +50,7 @@ export async function createWorkout(
errors: {
title: ["Workout with this title already exists."],
},
message: `"${title}" workout already exists`,
message: `${title} workout already exists`,
};
}

Expand All @@ -66,14 +66,14 @@ export async function createWorkout(
revalidatePath("/home");

return {
status: "success",
status: "success-redirect",
message: `${title} workout created`,
};
} catch (error) {
console.log(error);
return {
status: "error",
message: "Database Error: Workout could not be created",
message: "Failed to create workout...",
};
}
}
Expand All @@ -95,7 +95,7 @@ export async function editWorkout(
return {
status: "error",
errors: isValidWorkout.error.flatten().fieldErrors,
message: "Workout could not be edited",
message: "Invalid workout data",
};
}

Expand Down Expand Up @@ -142,7 +142,7 @@ export async function editWorkout(
console.log(error);
return {
status: "error",
message: "Database Error: Workout could not be edited",
message: "Failed to edit workout",
};
}
}
Expand All @@ -166,7 +166,7 @@ export async function removeWorkout(
console.error(err);
return {
status: "error",
message: "Database Error: Workout could not be removed",
message: "Failed to remove workout...",
};
}
}
Expand All @@ -193,7 +193,7 @@ export async function archiveWorkout(
console.error(err);
return {
status: "error",
message: "Database Error: Workout could not be archived",
message: "Failed to archive workout",
};
}
}
Expand Down Expand Up @@ -238,13 +238,13 @@ export async function submitDoneWorkout(

return {
status: "success-redirect",
message: "Workout completed",
message: "Workout submitted",
};
} catch (error) {
console.log(error);
return {
status: "error",
message: "Workout not completed",
message: "Failed to submit workout...",
};
}
}
Expand All @@ -265,7 +265,7 @@ export async function updateCurrentWorkout(
return {
status: "error",
errors: isValidWorkout.error.flatten().fieldErrors,
message: `${updatedCurrentWorkout.title} workout was not updated`,
message: `${updatedCurrentWorkout.title} was not updated`,
};
}

Expand All @@ -275,19 +275,19 @@ export async function updateCurrentWorkout(
.set({ exercises: [...updatedCurrentWorkout.exercises] })
.where(and(eq(workouts.id, workoutId), eq(workouts.status, "current")));

console.log("Workout successfully updated.");
console.log("Workout updated.");

revalidatePath("/home");

return {
status: "success-redirect",
message: `${updatedCurrentWorkout.title} workout successfully updated`,
message: `${updatedCurrentWorkout.title} workout updated`,
};
} catch (error) {
console.error(error);
return {
status: "error",
message: "Database Error: Workout could not be updated",
message: "Failed to update workout...",
};
}
}

0 comments on commit f144a98

Please sign in to comment.