Unilateral exercises logging

This commit is contained in:
AG
2025-12-03 23:30:32 +02:00
parent 50f3d4d49b
commit a632de65ea
24 changed files with 1656 additions and 244 deletions

View File

@@ -1,9 +1,8 @@
import express from 'express';
import { PrismaClient } from '@prisma/client';
import jwt from 'jsonwebtoken';
import prisma from '../lib/prisma';
const router = express.Router();
const prisma = new PrismaClient();
const JWT_SECRET = process.env.JWT_SECRET || 'secret';
// Middleware to check auth
@@ -46,9 +45,15 @@ router.get('/', async (req: any, res) => {
router.post('/', async (req: any, res) => {
try {
const userId = req.user.userId;
const { id, name, type, bodyWeightPercentage, isArchived } = req.body;
const { id, name, type, bodyWeightPercentage, isArchived, isUnilateral } = req.body;
const data = {
name,
type,
bodyWeightPercentage: bodyWeightPercentage ? parseFloat(bodyWeightPercentage) : undefined,
isArchived: !!isArchived,
isUnilateral: !!isUnilateral
};
// If id exists and belongs to user, update. Else create.
// Note: We can't update system exercises directly. If user edits a system exercise,
@@ -62,7 +67,7 @@ router.post('/', async (req: any, res) => {
const updated = await prisma.exercise.update({
where: { id },
data: { name, type, bodyWeightPercentage, isArchived }
data: data
});
return res.json(updated);
@@ -74,10 +79,11 @@ router.post('/', async (req: any, res) => {
data: {
id: id || undefined, // Use provided ID if available
userId,
name,
type,
bodyWeightPercentage,
isArchived: isArchived || false
name: data.name,
type: data.type,
bodyWeightPercentage: data.bodyWeightPercentage,
isArchived: data.isArchived,
isUnilateral: data.isUnilateral,
}
});
res.json(newExercise);