Skip to content

Commit abd5d49

Browse files
authored
Merge pull request #192 from Netsbump/feat/workout-element-model
refactor(training): migrate workout programming model to block-based …
2 parents 799724f + 9520a60 commit abd5d49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1674
-1206
lines changed

apps/api/src/modules/training/application/use-cases/complex.use-cases.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ export class ComplexUseCase implements IComplexUseCases {
107107
// 5. Create the complex
108108
const complex = new Complex();
109109
complex.complexCategory = complexCategory;
110-
complex.description = data.description || '';
111110

112111
// 6. Assign the creator user
113112
const user = await this.userUseCases.getOne(userId);
@@ -124,7 +123,6 @@ export class ComplexUseCase implements IComplexUseCases {
124123

125124
const exerciseComplex = new ExerciseComplex();
126125
exerciseComplex.order = exerciseData.order;
127-
exerciseComplex.reps = exerciseData.reps;
128126
exerciseComplex.exercise = exercise;
129127
exerciseComplex.complex = complex;
130128

@@ -160,10 +158,6 @@ export class ComplexUseCase implements IComplexUseCases {
160158
}
161159

162160
// 4. Update the complex properties
163-
if (data.description !== undefined) {
164-
complexToUpdate.description = data.description;
165-
}
166-
167161
if (data.complexCategory) {
168162
const complexCategory = await this.complexCategoryRepository.getOne(data.complexCategory, coachFilterConditions);
169163
if (!complexCategory) {
@@ -194,7 +188,6 @@ export class ComplexUseCase implements IComplexUseCases {
194188
exerciseComplex.exercise = exercise;
195189
exerciseComplex.complex = complexToUpdate;
196190
exerciseComplex.order = exerciseData.order;
197-
exerciseComplex.reps = exerciseData.reps;
198191

199192
complexToUpdate.exercises.add(exerciseComplex);
200193
}

apps/api/src/modules/training/application/use-cases/exercise.use-cases.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ export class ExerciseUseCase implements IExerciseUseCases {
126126
//5. Create exercise
127127
const exercise = new Exercise();
128128
exercise.name = data.name;
129-
if (data.description) {
130-
exercise.description = data.description;
131-
}
132129
exercise.exerciseCategory = exerciseCategory;
133130
if (data.englishName) {
134131
exercise.englishName = data.englishName;
@@ -177,9 +174,6 @@ export class ExerciseUseCase implements IExerciseUseCases {
177174
if (data.name) {
178175
exerciseToUpdate.name = data.name;
179176
}
180-
if (data.description !== undefined) {
181-
exerciseToUpdate.description = data.description;
182-
}
183177
if (data.englishName !== undefined) {
184178
exerciseToUpdate.englishName = data.englishName;
185179
}

apps/api/src/modules/training/application/use-cases/workout.use-cases.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ export class WorkoutUseCases implements IWorkoutUseCases {
145145

146146
//5. Create workout
147147
const workoutToCreate = new Workout();
148-
workoutToCreate.title = workout.title;
149148
workoutToCreate.description = workout.description || '';
150149
workoutToCreate.category = category;
151150

@@ -158,26 +157,23 @@ export class WorkoutUseCases implements IWorkoutUseCases {
158157
const workoutElement = new WorkoutElement();
159158
workoutElement.type = element.type;
160159
workoutElement.order = element.order;
161-
workoutElement.sets = element.sets;
162-
workoutElement.reps = element.reps;
163-
workoutElement.rest = element.rest;
164-
workoutElement.duration = element.duration;
165-
workoutElement.startWeight_percent = element.startWeight_percent;
166-
workoutElement.endWeight_percent = element.endWeight_percent;
160+
workoutElement.blocks = element.blocks;
161+
workoutElement.tempo = element.tempo;
162+
workoutElement.commentary = element.commentary;
167163

168164
if (element.type === WORKOUT_ELEMENT_TYPES.EXERCISE) {
169-
const exercise = await this.exerciseRepository.getOne(element.id, coachFilterConditions);
165+
const exercise = await this.exerciseRepository.getOne(element.exerciseId, coachFilterConditions);
170166
if (!exercise) {
171167
throw new ExerciseNotFoundException(
172-
`Exercise with ID ${element.id} not found or access denied`
168+
`Exercise with ID ${element.exerciseId} not found or access denied`
173169
);
174170
}
175171
workoutElement.exercise = exercise;
176172
} else {
177-
const complex = await this.complexRepository.getOne(element.id, coachFilterConditions);
173+
const complex = await this.complexRepository.getOne(element.complexId, coachFilterConditions);
178174
if (!complex) {
179175
throw new ComplexNotFoundException(
180-
`Complex with ID ${element.id} not found or access denied`
176+
`Complex with ID ${element.complexId} not found or access denied`
181177
);
182178
}
183179
workoutElement.complex = complex;
@@ -253,10 +249,6 @@ export class WorkoutUseCases implements IWorkoutUseCases {
253249
}
254250

255251
//4. Update workout
256-
if (workout.title) {
257-
workoutToUpdate.title = workout.title;
258-
}
259-
260252
if (workout.description !== undefined) {
261253
workoutToUpdate.description = workout.description;
262254
}
@@ -288,27 +280,24 @@ export class WorkoutUseCases implements IWorkoutUseCases {
288280
const workoutElement = new WorkoutElement();
289281
workoutElement.type = element.type;
290282
workoutElement.order = element.order;
291-
workoutElement.sets = element.sets;
292-
workoutElement.reps = element.reps;
293-
workoutElement.rest = element.rest;
294-
workoutElement.duration = element.duration;
295-
workoutElement.startWeight_percent = element.startWeight_percent;
296-
workoutElement.endWeight_percent = element.endWeight_percent;
283+
workoutElement.blocks = element.blocks;
284+
workoutElement.tempo = element.tempo;
285+
workoutElement.commentary = element.commentary;
297286
workoutElement.workout = workoutToUpdate;
298287

299288
if (element.type === WORKOUT_ELEMENT_TYPES.EXERCISE) {
300-
const exercise = await this.exerciseRepository.getOne(element.id, coachFilterConditions);
289+
const exercise = await this.exerciseRepository.getOne(element.exerciseId, coachFilterConditions);
301290
if (!exercise) {
302291
throw new ExerciseNotFoundException(
303-
`Exercise with ID ${element.id} not found or access denied`
292+
`Exercise with ID ${element.exerciseId} not found or access denied`
304293
);
305294
}
306295
workoutElement.exercise = exercise;
307296
} else {
308-
const complex = await this.complexRepository.getOne(element.id, coachFilterConditions);
297+
const complex = await this.complexRepository.getOne(element.complexId, coachFilterConditions);
309298
if (!complex) {
310299
throw new ComplexNotFoundException(
311-
`Complex with ID ${element.id} not found or access denied`
300+
`Complex with ID ${element.complexId} not found or access denied`
312301
);
313302
}
314303
workoutElement.complex = complex;

apps/api/src/modules/training/domain/complex.entity.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ export class Complex {
2424
)
2525
exercises = new Collection<ExerciseComplex>(this);
2626

27-
@Property({ nullable: true })
28-
description?: string;
29-
3027
@Property({ onCreate: () => new Date() })
3128
createdAt: Date = new Date();
3229

apps/api/src/modules/training/domain/exercise-complex.entity.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export class ExerciseComplex {
1313
@Property()
1414
order!: number;
1515

16-
@Property({ default: 1 })
17-
reps!: number;
18-
1916
@Property({ onCreate: () => new Date() })
2017
createdAt: Date = new Date();
2118

apps/api/src/modules/training/domain/exercise.entity.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export class Exercise {
2020
@Property()
2121
name!: string;
2222

23-
@Property({ nullable: true })
24-
description?: string;
25-
2623
@Property({ nullable: true })
2724
englishName?: string;
2825

apps/api/src/modules/training/domain/workout-element.entity.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { Complex } from './complex.entity';
1010
import { Exercise } from './exercise.entity';
1111
import { Workout } from './workout.entity';
12+
import { BlockConfigDto } from '@dropit/schemas';
1213

1314
export const WORKOUT_ELEMENT_TYPES = {
1415
EXERCISE: 'exercise',
@@ -42,29 +43,17 @@ export class WorkoutElement {
4243
@ManyToOne(() => Complex, { nullable: true, deleteRule: 'cascade' })
4344
complex?: Complex;
4445

46+
@Property({ type: 'jsonb' })
47+
blocks: BlockConfigDto[] = [];
48+
4549
@Property()
4650
order!: number;
4751

48-
@Property({ default: 1 })
49-
sets!: number;
50-
51-
@Property({ default: 1 })
52-
reps!: number;
53-
54-
@Property({ nullable: true })
55-
rest?: number;
56-
57-
@Property({ nullable: true })
58-
duration?: number;
59-
60-
@Property({ nullable: true })
61-
description?: string;
62-
6352
@Property({ nullable: true })
64-
startWeight_percent?: number;
53+
tempo?: string;
6554

6655
@Property({ nullable: true })
67-
endWeight_percent?: number;
56+
commentary?: string;
6857

6958
@Property({ onCreate: () => new Date() })
7059
createdAt: Date = new Date();

apps/api/src/modules/training/domain/workout.entity.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ export class Workout {
1616
@PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })
1717
id!: string;
1818

19-
@Property()
20-
title!: string;
21-
2219
@Property()
2320
description!: string;
2421

@@ -28,7 +25,6 @@ export class Workout {
2825
@ManyToOne(() => User, { nullable: true, deleteRule: 'cascade'})
2926
createdBy!: User | null;
3027

31-
3228
@OneToMany(
3329
() => WorkoutElement,
3430
(workoutElement) => workoutElement.workout

apps/api/src/modules/training/interface/mappers/complex.mapper.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ export const ComplexMapper = {
1818
id: exercise.exerciseCategory.id,
1919
name: exercise.exerciseCategory.name,
2020
},
21-
description: exercise.description,
2221
video: exercise.video?.id,
2322
englishName: exercise.englishName,
2423
shortName: exercise.shortName,
2524
order: exerciseComplex.order,
26-
reps: exerciseComplex.reps,
2725
};
2826
}),
29-
description: complex.description,
3027
};
3128
},
3229

apps/api/src/modules/training/interface/mappers/exercise.mapper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const ExerciseMapper = {
1111
name: exercise.exerciseCategory.name,
1212
},
1313
video: exercise.video?.id,
14-
description: exercise.description,
1514
englishName: exercise.englishName,
1615
shortName: exercise.shortName,
1716
};

0 commit comments

Comments
 (0)