Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export class ComplexUseCase implements IComplexUseCases {
// 5. Create the complex
const complex = new Complex();
complex.complexCategory = complexCategory;
complex.description = data.description || '';

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

const exerciseComplex = new ExerciseComplex();
exerciseComplex.order = exerciseData.order;
exerciseComplex.reps = exerciseData.reps;
exerciseComplex.exercise = exercise;
exerciseComplex.complex = complex;

Expand Down Expand Up @@ -160,10 +158,6 @@ export class ComplexUseCase implements IComplexUseCases {
}

// 4. Update the complex properties
if (data.description !== undefined) {
complexToUpdate.description = data.description;
}

if (data.complexCategory) {
const complexCategory = await this.complexCategoryRepository.getOne(data.complexCategory, coachFilterConditions);
if (!complexCategory) {
Expand Down Expand Up @@ -194,7 +188,6 @@ export class ComplexUseCase implements IComplexUseCases {
exerciseComplex.exercise = exercise;
exerciseComplex.complex = complexToUpdate;
exerciseComplex.order = exerciseData.order;
exerciseComplex.reps = exerciseData.reps;

complexToUpdate.exercises.add(exerciseComplex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ export class ExerciseUseCase implements IExerciseUseCases {
//5. Create exercise
const exercise = new Exercise();
exercise.name = data.name;
if (data.description) {
exercise.description = data.description;
}
exercise.exerciseCategory = exerciseCategory;
if (data.englishName) {
exercise.englishName = data.englishName;
Expand Down Expand Up @@ -177,9 +174,6 @@ export class ExerciseUseCase implements IExerciseUseCases {
if (data.name) {
exerciseToUpdate.name = data.name;
}
if (data.description !== undefined) {
exerciseToUpdate.description = data.description;
}
if (data.englishName !== undefined) {
exerciseToUpdate.englishName = data.englishName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export class WorkoutUseCases implements IWorkoutUseCases {

//5. Create workout
const workoutToCreate = new Workout();
workoutToCreate.title = workout.title;
workoutToCreate.description = workout.description || '';
workoutToCreate.category = category;

Expand All @@ -158,26 +157,23 @@ export class WorkoutUseCases implements IWorkoutUseCases {
const workoutElement = new WorkoutElement();
workoutElement.type = element.type;
workoutElement.order = element.order;
workoutElement.sets = element.sets;
workoutElement.reps = element.reps;
workoutElement.rest = element.rest;
workoutElement.duration = element.duration;
workoutElement.startWeight_percent = element.startWeight_percent;
workoutElement.endWeight_percent = element.endWeight_percent;
workoutElement.blocks = element.blocks;
workoutElement.tempo = element.tempo;
workoutElement.commentary = element.commentary;

if (element.type === WORKOUT_ELEMENT_TYPES.EXERCISE) {
const exercise = await this.exerciseRepository.getOne(element.id, coachFilterConditions);
const exercise = await this.exerciseRepository.getOne(element.exerciseId, coachFilterConditions);
if (!exercise) {
throw new ExerciseNotFoundException(
`Exercise with ID ${element.id} not found or access denied`
`Exercise with ID ${element.exerciseId} not found or access denied`
);
}
workoutElement.exercise = exercise;
} else {
const complex = await this.complexRepository.getOne(element.id, coachFilterConditions);
const complex = await this.complexRepository.getOne(element.complexId, coachFilterConditions);
if (!complex) {
throw new ComplexNotFoundException(
`Complex with ID ${element.id} not found or access denied`
`Complex with ID ${element.complexId} not found or access denied`
);
}
workoutElement.complex = complex;
Expand Down Expand Up @@ -253,10 +249,6 @@ export class WorkoutUseCases implements IWorkoutUseCases {
}

//4. Update workout
if (workout.title) {
workoutToUpdate.title = workout.title;
}

if (workout.description !== undefined) {
workoutToUpdate.description = workout.description;
}
Expand Down Expand Up @@ -288,27 +280,24 @@ export class WorkoutUseCases implements IWorkoutUseCases {
const workoutElement = new WorkoutElement();
workoutElement.type = element.type;
workoutElement.order = element.order;
workoutElement.sets = element.sets;
workoutElement.reps = element.reps;
workoutElement.rest = element.rest;
workoutElement.duration = element.duration;
workoutElement.startWeight_percent = element.startWeight_percent;
workoutElement.endWeight_percent = element.endWeight_percent;
workoutElement.blocks = element.blocks;
workoutElement.tempo = element.tempo;
workoutElement.commentary = element.commentary;
workoutElement.workout = workoutToUpdate;

if (element.type === WORKOUT_ELEMENT_TYPES.EXERCISE) {
const exercise = await this.exerciseRepository.getOne(element.id, coachFilterConditions);
const exercise = await this.exerciseRepository.getOne(element.exerciseId, coachFilterConditions);
if (!exercise) {
throw new ExerciseNotFoundException(
`Exercise with ID ${element.id} not found or access denied`
`Exercise with ID ${element.exerciseId} not found or access denied`
);
}
workoutElement.exercise = exercise;
} else {
const complex = await this.complexRepository.getOne(element.id, coachFilterConditions);
const complex = await this.complexRepository.getOne(element.complexId, coachFilterConditions);
if (!complex) {
throw new ComplexNotFoundException(
`Complex with ID ${element.id} not found or access denied`
`Complex with ID ${element.complexId} not found or access denied`
);
}
workoutElement.complex = complex;
Expand Down
3 changes: 0 additions & 3 deletions apps/api/src/modules/training/domain/complex.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export class Complex {
)
exercises = new Collection<ExerciseComplex>(this);

@Property({ nullable: true })
description?: string;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export class ExerciseComplex {
@Property()
order!: number;

@Property({ default: 1 })
reps!: number;

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

Expand Down
3 changes: 0 additions & 3 deletions apps/api/src/modules/training/domain/exercise.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export class Exercise {
@Property()
name!: string;

@Property({ nullable: true })
description?: string;

@Property({ nullable: true })
englishName?: string;

Expand Down
23 changes: 6 additions & 17 deletions apps/api/src/modules/training/domain/workout-element.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Complex } from './complex.entity';
import { Exercise } from './exercise.entity';
import { Workout } from './workout.entity';
import { BlockConfigDto } from '@dropit/schemas';

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

@Property({ type: 'jsonb' })
blocks: BlockConfigDto[] = [];

@Property()
order!: number;

@Property({ default: 1 })
sets!: number;

@Property({ default: 1 })
reps!: number;

@Property({ nullable: true })
rest?: number;

@Property({ nullable: true })
duration?: number;

@Property({ nullable: true })
description?: string;

@Property({ nullable: true })
startWeight_percent?: number;
tempo?: string;

@Property({ nullable: true })
endWeight_percent?: number;
commentary?: string;

@Property({ onCreate: () => new Date() })
createdAt: Date = new Date();
Expand Down
4 changes: 0 additions & 4 deletions apps/api/src/modules/training/domain/workout.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ export class Workout {
@PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })
id!: string;

@Property()
title!: string;

@Property()
description!: string;

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


@OneToMany(
() => WorkoutElement,
(workoutElement) => workoutElement.workout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ export const ComplexMapper = {
id: exercise.exerciseCategory.id,
name: exercise.exerciseCategory.name,
},
description: exercise.description,
video: exercise.video?.id,
englishName: exercise.englishName,
shortName: exercise.shortName,
order: exerciseComplex.order,
reps: exerciseComplex.reps,
};
}),
description: complex.description,
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const ExerciseMapper = {
name: exercise.exerciseCategory.name,
},
video: exercise.video?.id,
description: exercise.description,
englishName: exercise.englishName,
shortName: exercise.shortName,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ export const WorkoutMapper = {
const baseElement = {
id: element.id,
order: element.order,
reps: element.reps,
sets: element.sets,
rest: element.rest,
startWeight_percent: element.startWeight_percent,
tempo: element.tempo,
commentary: element.commentary,
blocks: element.blocks,
};

if (isExerciseElement(element)) {
Expand All @@ -33,7 +32,6 @@ export const WorkoutMapper = {
exercise: {
id: element.exercise.id,
name: element.exercise.name,
description: element.exercise.description,
exerciseCategory: {
id: element.exercise.exerciseCategory.id,
name: element.exercise.exerciseCategory.name,
Expand All @@ -51,15 +49,13 @@ export const WorkoutMapper = {
type: 'complex' as const,
complex: {
id: element.complex.id,
description: element.complex.description,
complexCategory: {
id: element.complex.complexCategory.id,
name: element.complex.complexCategory.name,
},
exercises: element.complex.exercises.getItems().map((ex: ExerciseComplex) => ({
id: ex.exercise.id,
name: ex.exercise.name,
description: ex.exercise.description,
exerciseCategory: {
id: ex.exercise.exerciseCategory.id,
name: ex.exercise.exerciseCategory.name,
Expand All @@ -68,7 +64,6 @@ export const WorkoutMapper = {
englishName: ex.exercise.englishName,
shortName: ex.exercise.shortName,
order: ex.order,
reps: ex.reps,
})),
},
};
Expand All @@ -80,7 +75,6 @@ export const WorkoutMapper = {

return {
id: workout.id,
title: workout.title,
workoutCategory: workout.category.name,
description: workout.description,
elements,
Expand Down
Loading