c5e3719a0c
- 5-tab layout (Profile, History, Workout, Exercises, Measure) with shared header nav - Workout system: template CRUD, active workout on /fitness/workout/active with localStorage persistence, pause/resume timer, rest timer, RPE input - Shared workout singleton (getWorkout) so active workout state is accessible across all fitness routes - Floating workout FAB indicator on all /fitness routes when workout is active - AddActionButton component for button-based FABs (measure + template creation) - Profile page with workouts-per-week bar chart and weight line chart with SMA trend line + ±1σ confidence band - Exercise detail with history, charts, and records tabs using static exercise data - Session history with grouped-by-month list, session detail with stats/PRs - Body measurements with latest values, body part display, add form - Card styling matching rosary/prayer route patterns (accent-dark, nord5 light, box-shadow, hover lift) - FitnessChart: fix SSR hang by moving Chart.register to client-side, remove redundant $effect - Exercise API: use static in-repo data instead of empty MongoDB collection - Workout finish: include exercise name for WorkoutSession model validation
164 lines
3.5 KiB
TypeScript
164 lines
3.5 KiB
TypeScript
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { requireAuth } from '$lib/server/middleware/auth';
|
|
import { dbConnect } from '$utils/db';
|
|
import { WorkoutTemplate } from '$models/WorkoutTemplate';
|
|
|
|
const defaultTemplates = [
|
|
{
|
|
name: 'Day 1 - Pull',
|
|
description: 'Back and biceps focused pull day',
|
|
exercises: [
|
|
{
|
|
exerciseId: 'bent-over-row-barbell',
|
|
sets: [
|
|
{ reps: 10, weight: 60, rpe: 7 },
|
|
{ reps: 10, weight: 60, rpe: 8 },
|
|
{ reps: 10, weight: 60, rpe: 9 }
|
|
],
|
|
restTime: 120
|
|
},
|
|
{
|
|
exerciseId: 'pull-up',
|
|
sets: [
|
|
{ reps: 6, rpe: 8 },
|
|
{ reps: 6, rpe: 8 },
|
|
{ reps: 6, rpe: 9 }
|
|
],
|
|
restTime: 120
|
|
},
|
|
{
|
|
exerciseId: 'lateral-raise-dumbbell',
|
|
sets: [
|
|
{ reps: 15, weight: 10, rpe: 7 },
|
|
{ reps: 15, weight: 10, rpe: 8 }
|
|
],
|
|
restTime: 90
|
|
},
|
|
{
|
|
exerciseId: 'front-raise-dumbbell',
|
|
sets: [
|
|
{ reps: 10, weight: 10, rpe: 7 },
|
|
{ reps: 10, weight: 10, rpe: 8 }
|
|
],
|
|
restTime: 90
|
|
}
|
|
]
|
|
},
|
|
{
|
|
name: 'Day 2 - Push',
|
|
description: 'Chest, shoulders, and triceps push day',
|
|
exercises: [
|
|
{
|
|
exerciseId: 'bench-press-barbell',
|
|
sets: [
|
|
{ reps: 8, weight: 80, rpe: 7 },
|
|
{ reps: 8, weight: 80, rpe: 8 },
|
|
{ reps: 8, weight: 80, rpe: 9 }
|
|
],
|
|
restTime: 120
|
|
},
|
|
{
|
|
exerciseId: 'incline-bench-press-barbell',
|
|
sets: [
|
|
{ reps: 10, weight: 60, rpe: 7 },
|
|
{ reps: 10, weight: 60, rpe: 8 }
|
|
],
|
|
restTime: 120
|
|
},
|
|
{
|
|
exerciseId: 'skullcrusher-dumbbell',
|
|
sets: [
|
|
{ reps: 15, weight: 15, rpe: 7 },
|
|
{ reps: 15, weight: 15, rpe: 8 }
|
|
],
|
|
restTime: 90
|
|
},
|
|
{
|
|
exerciseId: 'hammer-curl-dumbbell',
|
|
sets: [
|
|
{ reps: 15, weight: 12, rpe: 7 },
|
|
{ reps: 15, weight: 12, rpe: 8 }
|
|
],
|
|
restTime: 90
|
|
},
|
|
{
|
|
exerciseId: 'bicep-curl-dumbbell',
|
|
sets: [
|
|
{ reps: 15, weight: 10, rpe: 7 },
|
|
{ reps: 15, weight: 10, rpe: 8 }
|
|
],
|
|
restTime: 90
|
|
}
|
|
]
|
|
},
|
|
{
|
|
name: 'Day 3 - Legs',
|
|
description: 'Lower body leg day',
|
|
exercises: [
|
|
{
|
|
exerciseId: 'squat-barbell',
|
|
sets: [
|
|
{ reps: 8, weight: 80, rpe: 7 },
|
|
{ reps: 8, weight: 80, rpe: 8 },
|
|
{ reps: 8, weight: 80, rpe: 9 }
|
|
],
|
|
restTime: 150
|
|
},
|
|
{
|
|
exerciseId: 'romanian-deadlift-barbell',
|
|
sets: [
|
|
{ reps: 10, weight: 70, rpe: 7 },
|
|
{ reps: 10, weight: 70, rpe: 8 }
|
|
],
|
|
restTime: 120
|
|
},
|
|
{
|
|
exerciseId: 'leg-press-machine',
|
|
sets: [
|
|
{ reps: 12, weight: 100, rpe: 7 },
|
|
{ reps: 12, weight: 100, rpe: 8 }
|
|
],
|
|
restTime: 120
|
|
},
|
|
{
|
|
exerciseId: 'leg-curl-machine',
|
|
sets: [
|
|
{ reps: 12, weight: 40, rpe: 7 },
|
|
{ reps: 12, weight: 40, rpe: 8 }
|
|
],
|
|
restTime: 90
|
|
},
|
|
{
|
|
exerciseId: 'calf-raise-machine',
|
|
sets: [
|
|
{ reps: 15, weight: 60, rpe: 7 },
|
|
{ reps: 15, weight: 60, rpe: 8 }
|
|
],
|
|
restTime: 60
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
export const POST: RequestHandler = async ({ locals }) => {
|
|
const user = await requireAuth(locals);
|
|
await dbConnect();
|
|
|
|
// Check if user already has templates (don't re-seed)
|
|
const existingCount = await WorkoutTemplate.countDocuments({ createdBy: user.nickname });
|
|
if (existingCount > 0) {
|
|
return json({ message: 'Templates already exist', seeded: false });
|
|
}
|
|
|
|
const templates = await WorkoutTemplate.insertMany(
|
|
defaultTemplates.map((t) => ({
|
|
...t,
|
|
createdBy: user.nickname,
|
|
isDefault: true
|
|
}))
|
|
);
|
|
|
|
return json({ message: 'Default templates created', templates, seeded: true }, { status: 201 });
|
|
};
|