trainingpeaks-sdk
Version:
TypeScript SDK for TrainingPeaks API integration
48 lines (47 loc) • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWorkoutsListEntrypoint = void 0;
const http_errors_1 = require("../../adapters/errors/http-errors.js");
const error_codes_1 = require("../../domain/errors/error-codes.js");
const shared_1 = require("../../shared/index.js");
const getWorkoutsList = async (command, deps) => {
try {
const athleteId = command.athleteId ||
(await (0, shared_1.getAthleteIdFromSession)({
sessionStorage: deps.sessionStorage,
logger: deps.logger,
}));
deps.logger.info('Get workouts list entrypoint called', {
athleteId,
startDate: command.startDate,
endDate: command.endDate,
});
const apiResponse = await deps.tpRepository.getWorkoutsList({
athleteId,
startDate: command.startDate,
endDate: command.endDate,
});
return apiResponse;
}
catch (error) {
deps.logger.error('Failed to get workouts list', { error });
if ((0, http_errors_1.isHttpError)(error)) {
throw error;
}
const httpErrorResponse = {
status: 500,
statusText: 'Internal Server Error',
data: {
message: error instanceof Error
? error.message
: error_codes_1.ERROR_MESSAGES[error_codes_1.ERROR_CODES.WORKOUT_LIST_ERROR],
},
};
throw (0, http_errors_1.createHttpError)(httpErrorResponse, {
url: 'workouts',
method: 'GET',
});
}
};
const getWorkoutsListEntrypoint = (dependencies) => (command) => getWorkoutsList(command, dependencies);
exports.getWorkoutsListEntrypoint = getWorkoutsListEntrypoint;