trainingpeaks-sdk
Version:
TypeScript SDK for TrainingPeaks API integration
60 lines (59 loc) • 1.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkoutStepBuilder = void 0;
const domain_errors_1 = require("../../domain/errors/domain-errors.js");
const types_1 = require("../../types/index.js");
class WorkoutStepBuilder {
constructor() {
this.step = {
name: '',
length: { value: 0, unit: types_1.LengthUnit.MINUTE },
targets: [],
intensityClass: types_1.IntensityClass.ACTIVE,
openDuration: false,
};
}
name(name) {
this.step = { ...this.step, name };
return this;
}
duration(minutes) {
this.step = {
...this.step,
length: { value: minutes, unit: types_1.LengthUnit.MINUTE },
};
return this;
}
distance(value, unit = types_1.LengthUnit.KILOMETER) {
this.step = { ...this.step, length: { value, unit } };
return this;
}
addTarget(minValue, maxValue) {
if (minValue < 0) {
throw new domain_errors_1.ValidationError('Minimum target value must be non-negative', 'minValue');
}
if (maxValue < 0) {
throw new domain_errors_1.ValidationError('Maximum target value must be non-negative', 'maxValue');
}
if (minValue >= maxValue) {
throw new domain_errors_1.ValidationError('Minimum target value must be less than maximum target value', 'target');
}
this.step = {
...this.step,
targets: [...this.step.targets, { minValue, maxValue }],
};
return this;
}
intensityClass(intensityClass) {
this.step = { ...this.step, intensityClass };
return this;
}
openDuration(open = true) {
this.step = { ...this.step, openDuration: open };
return this;
}
build() {
return { ...this.step };
}
}
exports.WorkoutStepBuilder = WorkoutStepBuilder;