Skip to content

Commit b5de61c

Browse files
committed
refactor: reorganize collections into domain folders
Each collection moves from a flat PascalCase file to its own kebab-case folder with index.ts. Tracking types relocate to collections/exercises/types.ts as the canonical source; the old trackingTypes.ts becomes a thin re-export shim until the frontend is migrated. A barrel at collections/index.ts keeps payload.config.ts to a single import.
1 parent 11da220 commit b5de61c

16 files changed

Lines changed: 85 additions & 84 deletions

File tree

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CollectionConfig } from 'payload'
2-
import { isAdmin, adminOrSelf, isAdminField } from '../access'
2+
import { isAdmin, adminOrSelf, isAdminField } from '../../access'
33

44
export const Clients: CollectionConfig = {
55
slug: 'clients',
@@ -10,13 +10,10 @@ export const Clients: CollectionConfig = {
1010
group: 'Konta',
1111
},
1212
access: {
13-
// Konta zakłada wyłącznie trener/admin (brak publicznej rejestracji)
1413
create: isAdmin,
15-
// Admin czyta wszystkich; klient tylko siebie
1614
read: adminOrSelf,
1715
update: adminOrSelf,
1816
delete: isAdmin,
19-
// Klienci nie mają dostępu do panelu Payload (logują się przez tracker)
2017
admin: () => false,
2118
},
2219
fields: [
@@ -26,7 +23,6 @@ export const Clients: CollectionConfig = {
2623
label: 'Imię i nazwisko',
2724
},
2825
{
29-
// Wszystkie plany tego klienta (klient ma wiele customowych planów)
3026
name: 'plans',
3127
type: 'join',
3228
collection: 'plans',
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CollectionConfig } from 'payload'
2-
import { isAdmin, isAuthenticated } from '../access'
3-
import { trackingOptions, DEFAULT_TRACKING } from '../trackingTypes'
2+
import { isAdmin, isAuthenticated } from '../../access'
3+
import { trackingOptions, DEFAULT_TRACKING } from './types'
44

55
export const Exercises: CollectionConfig = {
66
slug: 'exercises',
@@ -10,7 +10,6 @@ export const Exercises: CollectionConfig = {
1010
group: 'Katalog',
1111
},
1212
access: {
13-
// Katalog czytają wszyscy zalogowani (klient widzi wideo/opis); edytuje admin
1413
create: isAdmin,
1514
read: isAuthenticated,
1615
update: isAdmin,

src/collections/exercises/types.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Jedno źródło prawdy: typ pomiaru ćwiczenia → które metryki zbieramy.
3+
* Używane przez: formularz logowania (które inputy) i hook SetLog (czyszczenie pól spoza typu).
4+
*/
5+
6+
export type MetricField = 'weight' | 'reps' | 'rir' | 'distanceM' | 'durationSec'
7+
export type TrackingType = 'strength' | 'cardio'
8+
9+
export type UnitOption = { label: string; value: string; factor: number }
10+
export type MetricMeta = {
11+
label: string
12+
placeholder: string
13+
numeric: boolean
14+
// Pole złożone: wejście min + sek, w bazie suma sekund
15+
composite?: 'duration'
16+
// Jednostki wejścia na froncie; w bazie wartość bazowa (factor = ile jednostek bazowych na 1 wybraną)
17+
units?: { default: string; options: UnitOption[] }
18+
}
19+
20+
export const METRIC_FIELDS: Record<MetricField, MetricMeta> = {
21+
weight: { label: 'Ciężar (kg)', placeholder: 'ciężar', numeric: true },
22+
reps: { label: 'Powtórzenia', placeholder: 'powtórzenia', numeric: false },
23+
rir: { label: 'RIR', placeholder: 'RIR (rezerwa)', numeric: false },
24+
distanceM: { label: 'Dystans (m)', placeholder: 'dystans', numeric: true },
25+
durationSec: { label: 'Czas', placeholder: 'minuty / sekundy', numeric: true, composite: 'duration' },
26+
}
27+
28+
export const ALL_METRIC_FIELDS = Object.keys(METRIC_FIELDS) as MetricField[]
29+
30+
export const TRACKING: Record<TrackingType, { label: string; fields: MetricField[] }> = {
31+
strength: { label: 'Siłowe', fields: ['weight', 'reps', 'rir'] },
32+
cardio: { label: 'Cardio', fields: ['distanceM', 'durationSec'] },
33+
}
34+
35+
export const DEFAULT_TRACKING: TrackingType = 'strength'
36+
37+
/** Lista pól dla danego typu (z fallbackiem do domyślnego). */
38+
export const trackingFields = (t?: string | null): MetricField[] =>
39+
t && t in TRACKING ? TRACKING[t as TrackingType].fields : TRACKING[DEFAULT_TRACKING].fields
40+
41+
/** Opcje selecta dla Payload. */
42+
export const trackingOptions = (Object.keys(TRACKING) as TrackingType[]).map((value) => ({
43+
label: TRACKING[value].label,
44+
value,
45+
}))

src/collections/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export { Exercises } from './exercises'
2+
export { Plans } from './plans'
3+
export { Clients } from './clients'
4+
export { Users } from './users'
5+
export { Media } from './media'
6+
export { Microcycles } from './microcycles'
7+
export { Workouts } from './workouts'
8+
export { WorkoutGroups } from './workout-groups'
9+
export { WorkoutExerciseRows } from './workout-exercise-rows'
10+
export { WorkoutLogs } from './workout-logs'
11+
export { SetLogs } from './set-logs'
12+
export { RoundLogs } from './round-logs'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CollectionConfig } from 'payload'
2-
import { isAdmin, adminOrOwnByClient } from '../access'
2+
import { isAdmin, adminOrOwnByClient } from '../../access'
33

44
export const Plans: CollectionConfig = {
55
slug: 'plans',
@@ -10,7 +10,7 @@ export const Plans: CollectionConfig = {
1010
},
1111
access: {
1212
create: isAdmin,
13-
read: adminOrOwnByClient, // admin wszystko; klient tylko swoje plany
13+
read: adminOrOwnByClient,
1414
update: isAdmin,
1515
delete: isAdmin,
1616
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CollectionConfig } from 'payload'
2-
import { adminOrOwnByClient, isAdmin } from '../access'
2+
import { adminOrOwnByClient, isAdmin } from '../../access'
33

44
export const RoundLogs: CollectionConfig = {
55
slug: 'round-logs',
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CollectionConfig } from 'payload'
2-
import { adminOrOwnByClient } from '../access'
3-
import { trackingFields, ALL_METRIC_FIELDS } from '../trackingTypes'
2+
import { adminOrOwnByClient } from '../../access'
3+
import { trackingFields, ALL_METRIC_FIELDS } from '../exercises/types'
44

55
export const SetLogs: CollectionConfig = {
66
slug: 'set-logs',
@@ -19,7 +19,6 @@ export const SetLogs: CollectionConfig = {
1919
beforeValidate: [
2020
async ({ data, req }) => {
2121
if (!data) return data
22-
// Klient nie może logować do cudzej sesji
2322
if (req.user?.collection === 'clients' && data.session) {
2423
const session = await req.payload.findByID({
2524
collection: 'workout-logs',
@@ -31,7 +30,6 @@ export const SetLogs: CollectionConfig = {
3130
throw new Error('Nie możesz logować serii do cudzej sesji.')
3231
}
3332
}
34-
// Wyzeruj metryki spoza typu pomiaru ćwiczenia (czyste dane pod wykresy)
3533
if (data.exercise) {
3634
const ex = await req.payload.findByID({
3735
collection: 'exercises',
@@ -48,7 +46,6 @@ export const SetLogs: CollectionConfig = {
4846
],
4947
beforeChange: [
5048
({ data, req }) => {
51-
// Klient zawsze loguje na siebie (ignoruj client z frontu)
5249
if (req.user?.collection === 'clients') {
5350
data.client = req.user.id
5451
}
@@ -72,14 +69,12 @@ export const SetLogs: CollectionConfig = {
7269
defaultValue: ({ user }) => (user?.collection === 'clients' ? user.id : undefined),
7370
},
7471
{
75-
// Snapshot — relacja do katalogu (progres między treningami)
7672
name: 'exercise',
7773
type: 'relationship',
7874
relationTo: 'exercises',
7975
label: 'Ćwiczenie (katalog)',
8076
},
8177
{
82-
// Snapshot tekstowy — trwałość historii nawet po usunięciu z katalogu
8378
name: 'exerciseName',
8479
type: 'text',
8580
label: 'Ćwiczenie (nazwa, migawka)',
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ export const Users: CollectionConfig = {
66
useAsTitle: 'email',
77
},
88
auth: true,
9-
fields: [
10-
// Email added by default
11-
// Add more fields as needed
12-
],
9+
fields: [],
1310
versions: false,
1411
}

0 commit comments

Comments
 (0)