User already exists message is red. Modals to the viewport center. Fixed Quit option: it deletes the session.

This commit is contained in:
AG
2025-12-01 07:23:47 +02:00
parent 0290bbabd7
commit ead48fb249
9 changed files with 70 additions and 20 deletions

Binary file not shown.

View File

@@ -81,6 +81,16 @@ router.post('/', async (req: any, res) => {
return res.json(updated);
} else {
// Create
// If creating a new active session (endTime is null), check if one already exists
if (!end) {
const active = await prisma.workoutSession.findFirst({
where: { userId, endTime: null }
});
if (active) {
return res.status(400).json({ error: 'An active session already exists' });
}
}
const created = await prisma.workoutSession.create({
data: {
id, // Use provided ID or let DB gen? Frontend usually generates UUIDs.
@@ -282,7 +292,7 @@ router.post('/active/log-set', async (req: any, res) => {
break;
}
}
const mappedNewSet = {
...newSet,
exerciseName: newSet.exercise.name,
@@ -299,7 +309,7 @@ router.post('/active/log-set', async (req: any, res) => {
exerciseName: newSet.exercise.name,
type: newSet.exercise.type
};
res.json({ success: true, newSet: mappedNewSet, activeExerciseId: null });
} catch (error) {
@@ -381,23 +391,14 @@ router.delete('/active', async (req: any, res) => {
try {
const userId = req.user.userId;
// Find active session
const activeSession = await prisma.workoutSession.findFirst({
// Delete all active sessions for this user to ensure clean state
await prisma.workoutSession.deleteMany({
where: {
userId,
endTime: null
}
});
if (!activeSession) {
return res.json({ success: true, message: 'No active session found' });
}
// Delete the session (cascade will delete sets)
await prisma.workoutSession.delete({
where: { id: activeSession.id }
});
res.json({ success: true });
} catch (error) {
console.error(error);