Katalog: seed 404 cwiczen i 31 pozycji sprzetu z CSV, partia Lydki (reset BUILTIN do seed_version 2)
This commit is contained in:
70
api/src/data/equipment.ts
Normal file
70
api/src/data/equipment.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import type { EquipmentKind, EquipmentSpec } from '../lib/equipmentSpec.js';
|
||||
|
||||
/** Slug po nazwie sprzętu (bez diakrytyków) — spójny key między seedem a testami. */
|
||||
export function equipmentSlugFromName(name: string): string {
|
||||
return name
|
||||
.normalize('NFKD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.replace(/ł/g, 'l')
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
}
|
||||
|
||||
export interface EquipmentSeed {
|
||||
slug: string;
|
||||
name: string;
|
||||
kind: EquipmentKind;
|
||||
spec: EquipmentSpec | null;
|
||||
description: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equipment (machine/device) catalog — slug → Polish display name.
|
||||
* The slug is the stable key used by the exercise seed data; the name is what
|
||||
* admins and gym owners see and pick from.
|
||||
* `kind` determines the shape of the type-specific `spec` payload:
|
||||
* DUMBBELL/KETTLEBELL/CABLE/MACHINE → { minKg, maxKg } (available load range)
|
||||
* BARBELL/BENCH → { maxLoadKg } (max total load)
|
||||
* CARDIO → { maxSpeedKmh?, maxInclinePct? }
|
||||
* BODYWEIGHT/OTHER → no spec
|
||||
*/
|
||||
export const EQUIPMENT: EquipmentSeed[] = [
|
||||
{ slug: 'barbell', name: 'Sztanga', kind: 'BARBELL', spec: { maxLoadKg: 100 }, description: 'Sztanga z talerzami.' },
|
||||
{ slug: 'dumbbells', name: 'Hantle', kind: 'DUMBBELL', spec: { minKg: 2.5, maxKg: 25 }, description: 'Hantle wolne.' },
|
||||
{ slug: 'bodyweight', name: 'Masa ciała', kind: 'BODYWEIGHT', spec: null, description: 'Ćwiczenia z masą ciała.' },
|
||||
{ slug: 'cable', name: 'Wyciąg', kind: 'CABLE', spec: { minKg: 5, maxKg: 50 }, description: 'Wyciąg linowy.' },
|
||||
{ slug: 'dip-bars', name: 'Drążek do dipów', kind: 'BODYWEIGHT', spec: null, description: 'Stojak do dipów.' },
|
||||
{ slug: 'pull-up-bar', name: 'Drążek do podciągania', kind: 'BODYWEIGHT', spec: null, description: 'Drążek do podciągania.' },
|
||||
{ slug: 'leg-press', name: 'Leg press', kind: 'MACHINE', spec: { minKg: 20, maxKg: 120 }, description: 'Maszyna do prostowania nóg.' },
|
||||
{ slug: 'leg-curl', name: 'Leg curl', kind: 'MACHINE', spec: { minKg: 10, maxKg: 60 }, description: 'Maszyna do uginania nóg.' },
|
||||
// Katalog sprzętu z docs/database/maszyna-lub-przedmiot.csv (bez pozycji pokrywających się z powyższymi):
|
||||
{ slug: 'brama', name: 'Brama', kind: 'CABLE', spec: { minKg: 5, maxKg: 50 }, description: 'Brama siłowa (wyciąg wielostanowiskowy).' },
|
||||
{ slug: 'guma-oporowa', name: 'Guma oporowa', kind: 'OTHER', spec: null, description: 'Guma oporowa do asysty i oporu.' },
|
||||
{ slug: 'laweczka-plaska', name: 'Ławeczka płaska', kind: 'BENCH', spec: { maxLoadKg: 300 }, description: 'Ławka płaska ze stojakami.' },
|
||||
{ slug: 'laweczka-skosna', name: 'Ławeczka skośna', kind: 'BENCH', spec: { maxLoadKg: 300 }, description: 'Ławka ze skosem dodatnim/ujemnym.' },
|
||||
{ slug: 'suwnica-smitha', name: 'Suwnica smitha', kind: 'MACHINE', spec: { minKg: 5, maxKg: 120 }, description: 'Suwnica Smitha.' },
|
||||
{ slug: 'butterfly', name: 'Butterfly', kind: 'MACHINE', spec: { minKg: 5, maxKg: 80 }, description: 'Maszyna butterfly (rozpiętki).' },
|
||||
{ slug: 'trx', name: 'TRX', kind: 'OTHER', spec: null, description: 'Zawiesia TRX.' },
|
||||
{ slug: 'porecze-do-dipow', name: 'Poręcze do dipów', kind: 'BODYWEIGHT', spec: null, description: 'Poręcze do dipów.' },
|
||||
{ slug: 'hammer', name: 'Hammer', kind: 'MACHINE', spec: { minKg: 5, maxKg: 100 }, description: 'Maszyna hammer strength.' },
|
||||
{ slug: 'drazek', name: 'Drążek', kind: 'BODYWEIGHT', spec: null, description: 'Drążek do podciągania i zwisów.' },
|
||||
{ slug: 'kettlebell', name: 'Kettlebell', kind: 'KETTLEBELL', spec: { minKg: 4, maxKg: 32 }, description: 'Kettlebell.' },
|
||||
{ slug: 'kolka', name: 'Kółka', kind: 'OTHER', spec: null, description: 'Kółka gimnastyczne.' },
|
||||
{ slug: 'laweczka-rzymska', name: 'Ławeczka rzymska', kind: 'BENCH', spec: { maxLoadKg: 150 }, description: 'Ławka rzymska (hyperextension).' },
|
||||
{ slug: 'shoulder-press', name: 'Shoulder Press', kind: 'MACHINE', spec: { minKg: 5, maxKg: 100 }, description: 'Maszyna do wyciskania na barki.' },
|
||||
{ slug: 'sztanga-lamana', name: 'Sztanga łamana', kind: 'BARBELL', spec: { maxLoadKg: 100 }, description: 'Sztanga łamana (EZ).' },
|
||||
{ slug: 'triceps-press', name: 'Triceps Press', kind: 'MACHINE', spec: { minKg: 5, maxKg: 80 }, description: 'Maszyna na triceps.' },
|
||||
{ slug: 'modlitewnik', name: 'Modlitewnik', kind: 'BENCH', spec: { maxLoadKg: 60 }, description: 'Modlitewnik do uginania biceps.' },
|
||||
{ slug: 'pilka-gimnastyczne', name: 'Piłka gimnastyczne', kind: 'OTHER', spec: null, description: 'Piłka gimnastyczna (fitball).' },
|
||||
{ slug: 'ab-wheel', name: 'Ab wheel', kind: 'OTHER', spec: null, description: 'Kółko do brzucha.' },
|
||||
{ slug: 'podwyzszenie-schodki', name: 'Podwyższenie / Schodki', kind: 'OTHER', spec: null, description: 'Podwyższenie lub schodki do wchodzenia.' },
|
||||
{ slug: 'skrzynia', name: 'Skrzynia', kind: 'OTHER', spec: null, description: 'Skrzynia plyometryczna.' },
|
||||
{ slug: 'leg-extension-leg-curl', name: 'Leg Extension / Leg Curl', kind: 'MACHINE', spec: { minKg: 5, maxKg: 100 }, description: 'Maszyna do prostowania i uginania nóg.' },
|
||||
{ slug: 'drabinka', name: 'Drabinka', kind: 'OTHER', spec: null, description: 'Drabinka gimnastyczna.' },
|
||||
{ slug: 'kierownica-talerz', name: 'Kierownica/ Talerz', kind: 'OTHER', spec: null, description: 'Kierownica trójkątna lub talerz obciążeniowy.' },
|
||||
{ slug: 'suwnica-na-nogi', name: 'Suwnica na nogi', kind: 'MACHINE', spec: { minKg: 10, maxKg: 200 }, description: 'Suwnica (prasa) na nogi.' },
|
||||
{ slug: 'glute-kickback-machine', name: 'Glute Kickback Machine', kind: 'MACHINE', spec: { minKg: 5, maxKg: 80 }, description: 'Maszyna na pośladki (kickback).' },
|
||||
{ slug: 'adductor', name: 'Adductor', kind: 'MACHINE', spec: { minKg: 5, maxKg: 80 }, description: 'Maszyna na przywodziciele/odwodziciele.' },
|
||||
{ slug: 'maszyna-na-lydki', name: 'Maszyna na łydki', kind: 'MACHINE', spec: { minKg: 5, maxKg: 120 }, description: 'Maszyna do wspięć na palce.' },
|
||||
];
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@ import 'dotenv/config';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { Prisma, PrismaClient } from '@prisma/client';
|
||||
import { EXERCISES, SEED_VERSION } from './data/exercises.js';
|
||||
import type { EquipmentKind, EquipmentSpec } from './lib/equipmentSpec.js';
|
||||
import { EQUIPMENT, equipmentSlugFromName } from './data/equipment.js';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
@@ -20,33 +20,7 @@ const FOCUS_AREAS: Array<{ name: string; muscle: string; description: string; se
|
||||
{ name: 'Biceps', muscle: 'biceps', description: 'Uginanie, podciąganie.', setsMin: 6, setsMax: 12 },
|
||||
{ name: 'Triceps', muscle: 'triceps', description: 'Osiadanie, wyciskanie francuskie.', setsMin: 6, setsMax: 12 },
|
||||
{ name: 'Brzuch / core', muscle: 'core', description: 'Plank, unoszenia nóg, stabilizacja.', setsMin: 8, setsMax: 16 },
|
||||
];
|
||||
|
||||
/**
|
||||
* Equipment (machine/device) catalog — slug → Polish display name.
|
||||
* The slug is the stable key used by the exercise seed data; the name is what
|
||||
* admins and gym owners see and pick from.
|
||||
* `kind` determines the shape of the type-specific `spec` payload:
|
||||
* DUMBBELL/KETTLEBELL/CABLE/MACHINE → { minKg, maxKg } (available load range)
|
||||
* BARBELL/BENCH → { maxLoadKg } (max total load)
|
||||
* CARDIO → { maxSpeedKmh?, maxInclinePct? }
|
||||
* BODYWEIGHT/OTHER → no spec
|
||||
*/
|
||||
const EQUIPMENT: Array<{
|
||||
slug: string;
|
||||
name: string;
|
||||
kind: EquipmentKind;
|
||||
spec: EquipmentSpec | null;
|
||||
description: string;
|
||||
}> = [
|
||||
{ slug: 'barbell', name: 'Sztanga', kind: 'BARBELL', spec: { maxLoadKg: 100 }, description: 'Sztanga z talerzami.' },
|
||||
{ slug: 'dumbbells', name: 'Hantle', kind: 'DUMBBELL', spec: { minKg: 2.5, maxKg: 25 }, description: 'Hantle wolne.' },
|
||||
{ slug: 'bodyweight', name: 'Masa ciała', kind: 'BODYWEIGHT', spec: null, description: 'Ćwiczenia z masą ciała.' },
|
||||
{ slug: 'cable', name: 'Wyciąg', kind: 'CABLE', spec: { minKg: 5, maxKg: 50 }, description: 'Wyciąg linowy.' },
|
||||
{ slug: 'dip-bars', name: 'Drążek do dipów', kind: 'BODYWEIGHT', spec: null, description: 'Stojak do dipów.' },
|
||||
{ slug: 'pull-up-bar', name: 'Drążek do podciągania', kind: 'BODYWEIGHT', spec: null, description: 'Drążek do podciągania.' },
|
||||
{ slug: 'leg-press', name: 'Leg press', kind: 'MACHINE', spec: { minKg: 20, maxKg: 120 }, description: 'Maszyna do prostowania nóg.' },
|
||||
{ slug: 'leg-curl', name: 'Leg curl', kind: 'MACHINE', spec: { minKg: 10, maxKg: 60 }, description: 'Maszyna do uginania nóg.' },
|
||||
{ name: 'Łydki', muscle: 'calves', description: 'Wspięcia na palce, prostowanie na maszynie.', setsMin: 6, setsMax: 14 },
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -68,7 +42,9 @@ async function seedEquipment() {
|
||||
async function resolveEquipmentIds(slugs: string[]): Promise<string[]> {
|
||||
const ids: string[] = [];
|
||||
for (const slug of slugs) {
|
||||
const known = EQUIPMENT.find((e) => e.slug === slug);
|
||||
const known =
|
||||
EQUIPMENT.find((e) => e.slug === slug) ??
|
||||
EQUIPMENT.find((e) => equipmentSlugFromName(e.name) === slug);
|
||||
const name = known?.name ?? slug;
|
||||
const eq = await prisma.equipment.upsert({
|
||||
where: { name },
|
||||
@@ -137,6 +113,26 @@ async function seedExercises() {
|
||||
console.log(`Seeded ${EXERCISES.length} exercises (seed_version=${SEED_VERSION})`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Porządki po resecie katalogu BUILTIN: usuwa ćwiczenia BUILTIN spoza bieżącego
|
||||
* katalogu (np. demo ze seed version 1), o ile nie są używane w planach/sesjach.
|
||||
* Ćwiczenia w użyciu zostają — usunięcie zniszczyłoby dane użytkownika.
|
||||
*/
|
||||
async function pruneStaleBuiltinExercises() {
|
||||
const currentSlugs = EXERCISES.map((e) => e.slug);
|
||||
const staleWhere = {
|
||||
source: 'BUILTIN' as const,
|
||||
slug: { notIn: currentSlugs },
|
||||
};
|
||||
const result = await prisma.exercise.deleteMany({
|
||||
where: { ...staleWhere, planExercises: { none: {} }, sessionExercises: { none: {} } },
|
||||
});
|
||||
const inUse = await prisma.exercise.count({ where: staleWhere });
|
||||
if (result.count) console.log(`Pruned ${result.count} stale BUILTIN exercises`);
|
||||
if (inUse)
|
||||
console.warn(`Kept ${inUse} stale BUILTIN exercises still referenced by plans/sessions`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Idempotent seed of the default focus areas — upsert by muscle key.
|
||||
*/
|
||||
@@ -144,8 +140,19 @@ async function seedFocusAreas() {
|
||||
for (const fa of FOCUS_AREAS) {
|
||||
await prisma.focusArea.upsert({
|
||||
where: { muscle: fa.muscle },
|
||||
update: { name: fa.name, description: fa.description, setsMin: fa.setsMin, setsMax: fa.setsMax },
|
||||
create: { name: fa.name, muscle: fa.muscle, description: fa.description, setsMin: fa.setsMin, setsMax: fa.setsMax },
|
||||
update: {
|
||||
name: fa.name,
|
||||
description: fa.description,
|
||||
setsMin: fa.setsMin,
|
||||
setsMax: fa.setsMax,
|
||||
},
|
||||
create: {
|
||||
name: fa.name,
|
||||
muscle: fa.muscle,
|
||||
description: fa.description,
|
||||
setsMin: fa.setsMin,
|
||||
setsMax: fa.setsMax,
|
||||
},
|
||||
});
|
||||
}
|
||||
console.log(`Seeded ${FOCUS_AREAS.length} focus areas`);
|
||||
@@ -183,6 +190,7 @@ async function seedFirstAdmin() {
|
||||
async function main() {
|
||||
await seedEquipment();
|
||||
await seedExercises();
|
||||
await pruneStaleBuiltinExercises();
|
||||
await seedFocusAreas();
|
||||
await seedFirstAdmin();
|
||||
}
|
||||
|
||||
63
api/test/unit/seed-catalog.test.ts
Normal file
63
api/test/unit/seed-catalog.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { EXERCISES } from '../../src/data/exercises.js';
|
||||
import { EQUIPMENT, equipmentSlugFromName } from '../../src/data/equipment.js';
|
||||
import { validateEquipmentSpec } from '../../src/lib/equipmentSpec.js';
|
||||
|
||||
/** Klucze mięśni obecne w katalogu (seed partii z docs/database/partia.csv). */
|
||||
const KNOWN_MUSCLES = new Set([
|
||||
'chest',
|
||||
'back',
|
||||
'shoulders',
|
||||
'triceps',
|
||||
'biceps',
|
||||
'core',
|
||||
'legs',
|
||||
'glutes',
|
||||
'forearms',
|
||||
'calves',
|
||||
]);
|
||||
|
||||
describe('katalog cwiczen (seed data)', () => {
|
||||
it('ma unikalne slugi i niepuste nazwy', () => {
|
||||
const slugs = EXERCISES.map((e) => e.slug);
|
||||
expect(new Set(slugs).size).toBe(slugs.length);
|
||||
for (const ex of EXERCISES) {
|
||||
expect(ex.name.trim().length).toBeGreaterThan(0);
|
||||
expect(ex.slug).toBe(ex.slug.trim().toLowerCase());
|
||||
}
|
||||
});
|
||||
|
||||
it('uzywa tylko znanych kluczy partii miesniowych', () => {
|
||||
for (const ex of EXERCISES) {
|
||||
expect(KNOWN_MUSCLES.has(ex.primaryMuscle)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('kazde cwiczenie wskazuje sprzet obecny w katalogu EQUIPMENT', () => {
|
||||
for (const ex of EXERCISES) {
|
||||
for (const slug of ex.equipment) {
|
||||
const known =
|
||||
EQUIPMENT.find((e) => e.slug === slug) ?? EQUIPMENT.find((e) => equipmentSlugFromName(e.name) === slug);
|
||||
expect(known, `sprzet ${slug} (cwiczenie ${ex.slug})`).toBeDefined();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('zawiera cwiczenia bez sprzetu (partia CSV: Brak)', () => {
|
||||
expect(EXERCISES.some((e) => e.equipment.length === 0)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('katalog sprzetu (seed data)', () => {
|
||||
it('ma unikalne nazwy i slugi', () => {
|
||||
expect(new Set(EQUIPMENT.map((e) => e.name)).size).toBe(EQUIPMENT.length);
|
||||
expect(new Set(EQUIPMENT.map((e) => e.slug)).size).toBe(EQUIPMENT.length);
|
||||
});
|
||||
|
||||
it('ma spec zgodny z rodzajem (validateEquipmentSpec)', () => {
|
||||
for (const eq of EQUIPMENT) {
|
||||
const result = validateEquipmentSpec(eq.kind, eq.spec);
|
||||
expect(result.ok, `spec dla ${eq.name} (${eq.kind})`).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,7 @@ export const MUSCLE_NAMES: Record<string, string> = {
|
||||
core: 'Core',
|
||||
glutes: 'Pośladki',
|
||||
forearms: 'Przedramię',
|
||||
calves: 'Łydki',
|
||||
};
|
||||
|
||||
// Indexed by API dayOfWeek convention: 1 = Monday ... 7 = Sunday (index 0 unused).
|
||||
|
||||
Reference in New Issue
Block a user