refactor: consolidate formatting utilities and add testing infrastructure
- Replace 8 duplicate formatCurrency functions with shared utility - Add comprehensive formatter utilities (currency, date, number, etc.) - Set up Vitest for unit testing with 38 passing tests - Set up Playwright for E2E testing - Consolidate database connection to single source (src/utils/db.ts) - Add auth middleware helpers to reduce code duplication - Fix display bug: remove spurious minus sign in recent activity amounts - Add path aliases for cleaner imports ($utils, $models) - Add project documentation (CODEMAP.md, REFACTORING_PLAN.md) Test coverage: 38 unit tests passing Build: successful with no breaking changes
This commit is contained in:
64
src/routes/api/fitness/seed-example/+server.ts
Normal file
64
src/routes/api/fitness/seed-example/+server.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { dbConnect } from '$utils/db';
|
||||
import { WorkoutTemplate } from '../../../../models/WorkoutTemplate';
|
||||
|
||||
// POST /api/fitness/seed-example - Create the example workout template
|
||||
export const POST: RequestHandler = async ({ locals }) => {
|
||||
const session = await locals.auth();
|
||||
if (!session || !session.user?.nickname) {
|
||||
return json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
await dbConnect();
|
||||
|
||||
// Check if example template already exists for this user
|
||||
const existingTemplate = await WorkoutTemplate.findOne({
|
||||
name: 'Push Day (Example)',
|
||||
createdBy: session.user.nickname
|
||||
});
|
||||
|
||||
if (existingTemplate) {
|
||||
return json({ message: 'Example template already exists', template: existingTemplate });
|
||||
}
|
||||
|
||||
// Create the example template with barbell squats and barbell bench press
|
||||
const exampleTemplate = new WorkoutTemplate({
|
||||
name: 'Push Day (Example)',
|
||||
description: 'A sample push workout with squats and bench press - 3 sets of 10 reps each at 90kg',
|
||||
exercises: [
|
||||
{
|
||||
name: 'Barbell Squats',
|
||||
sets: [
|
||||
{ reps: 10, weight: 90, rpe: 7 },
|
||||
{ reps: 10, weight: 90, rpe: 8 },
|
||||
{ reps: 10, weight: 90, rpe: 9 }
|
||||
],
|
||||
restTime: 120 // 2 minutes
|
||||
},
|
||||
{
|
||||
name: 'Barbell Bench Press',
|
||||
sets: [
|
||||
{ reps: 10, weight: 90, rpe: 7 },
|
||||
{ reps: 10, weight: 90, rpe: 8 },
|
||||
{ reps: 10, weight: 90, rpe: 9 }
|
||||
],
|
||||
restTime: 120 // 2 minutes
|
||||
}
|
||||
],
|
||||
isPublic: false,
|
||||
createdBy: session.user.nickname
|
||||
});
|
||||
|
||||
await exampleTemplate.save();
|
||||
|
||||
return json({
|
||||
message: 'Example template created successfully!',
|
||||
template: exampleTemplate
|
||||
}, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Error creating example template:', error);
|
||||
return json({ error: 'Failed to create example template' }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user