feat(Strava Node): Update to use sport type (#9462)

Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
This commit is contained in:
Giulio Cinelli 2024-05-22 09:49:51 +02:00 committed by GitHub
parent 62df4331d4
commit 9da93680c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 148 additions and 4 deletions

View file

@ -98,11 +98,80 @@ export const activityFields: INodeProperties[] = [
show: {
resource: ['activity'],
operation: ['create'],
'@version': [1],
},
},
default: '',
description: 'Type of activity. For example - Run, Ride etc.',
},
{
displayName: 'Sport Type',
name: 'sport_type',
type: 'options',
options: [
{ name: 'Alpine Ski', value: 'AlpineSki' },
{ name: 'Backcountry Ski', value: 'BackcountrySki' },
{ name: 'Badminton', value: 'Badminton' },
{ name: 'Canoeing', value: 'Canoeing' },
{ name: 'Crossfit', value: 'Crossfit' },
{ name: 'EBike Ride', value: 'EBikeRide' },
{ name: 'Elliptical', value: 'Elliptical' },
{ name: 'EMountain Bike Ride', value: 'EMountainBikeRide' },
{ name: 'Golf', value: 'Golf' },
{ name: 'Gravel Ride', value: 'GravelRide' },
{ name: 'Handcycle', value: 'Handcycle' },
{ name: 'HIIT', value: 'HighIntensityIntervalTraining' },
{ name: 'Hike', value: 'Hike' },
{ name: 'Ice Skate', value: 'IceSkate' },
{ name: 'Inline Skate', value: 'InlineSkate' },
{ name: 'Kayaking', value: 'Kayaking' },
{ name: 'Kitesurf', value: 'Kitesurf' },
{ name: 'Mountain Bike Ride', value: 'MountainBikeRide' },
{ name: 'Nordic Ski', value: 'NordicSki' },
{ name: 'Pickleball', value: 'Pickleball' },
{ name: 'Pilates', value: 'Pilates' },
{ name: 'Racquetball', value: 'Racquetball' },
{ name: 'Ride', value: 'Ride' },
{ name: 'Rock Climbing', value: 'RockClimbing' },
{ name: 'Roller Ski', value: 'RollerSki' },
{ name: 'Rowing', value: 'Rowing' },
{ name: 'Run', value: 'Run' },
{ name: 'Sail', value: 'Sail' },
{ name: 'Skateboard', value: 'Skateboard' },
{ name: 'Snowboard', value: 'Snowboard' },
{ name: 'Snowshoe', value: 'Snowshoe' },
{ name: 'Soccer', value: 'Soccer' },
{ name: 'Squash', value: 'Squash' },
{ name: 'Stair Stepper', value: 'StairStepper' },
{ name: 'Stand Up Paddling', value: 'StandUpPaddling' },
{ name: 'Surfing', value: 'Surfing' },
{ name: 'Swim', value: 'Swim' },
{ name: 'Table Tennis', value: 'TableTennis' },
{ name: 'Tennis', value: 'Tennis' },
{ name: 'Trail Run', value: 'TrailRun' },
{ name: 'Velomobile', value: 'Velomobile' },
{ name: 'Virtual Ride', value: 'VirtualRide' },
{ name: 'Virtual Row', value: 'VirtualRow' },
{ name: 'Virtual Run', value: 'VirtualRun' },
{ name: 'Walk', value: 'Walk' },
{ name: 'Weight Training', value: 'WeightTraining' },
{ name: 'Wheelchair', value: 'Wheelchair' },
{ name: 'Windsurf', value: 'Windsurf' },
{ name: 'Workout', value: 'Workout' },
{ name: 'Yoga', value: 'Yoga' },
],
default: 'Run',
description: 'Type of sport',
displayOptions: {
show: {
resource: ['activity'],
operation: ['create'],
},
hide: {
'@version': [1],
},
},
},
{
displayName: 'Start Date',
name: 'startDate',
@ -254,6 +323,75 @@ export const activityFields: INodeProperties[] = [
type: 'string',
default: '',
description: 'Type of activity. For example - Run, Ride etc.',
displayOptions: {
show: {
'@version': [1],
},
},
},
{
displayName: 'Sport Type',
name: 'sport_type',
type: 'options',
options: [
{ name: 'Alpine Ski', value: 'AlpineSki' },
{ name: 'Backcountry Ski', value: 'BackcountrySki' },
{ name: 'Badminton', value: 'Badminton' },
{ name: 'Canoeing', value: 'Canoeing' },
{ name: 'Crossfit', value: 'Crossfit' },
{ name: 'EBike Ride', value: 'EBikeRide' },
{ name: 'Elliptical', value: 'Elliptical' },
{ name: 'EMountain Bike Ride', value: 'EMountainBikeRide' },
{ name: 'Golf', value: 'Golf' },
{ name: 'Gravel Ride', value: 'GravelRide' },
{ name: 'Handcycle', value: 'Handcycle' },
{ name: 'HIIT', value: 'HighIntensityIntervalTraining' },
{ name: 'Hike', value: 'Hike' },
{ name: 'Ice Skate', value: 'IceSkate' },
{ name: 'Inline Skate', value: 'InlineSkate' },
{ name: 'Kayaking', value: 'Kayaking' },
{ name: 'Kitesurf', value: 'Kitesurf' },
{ name: 'Mountain Bike Ride', value: 'MountainBikeRide' },
{ name: 'Nordic Ski', value: 'NordicSki' },
{ name: 'Pickleball', value: 'Pickleball' },
{ name: 'Pilates', value: 'Pilates' },
{ name: 'Racquetball', value: 'Racquetball' },
{ name: 'Ride', value: 'Ride' },
{ name: 'Rock Climbing', value: 'RockClimbing' },
{ name: 'Roller Ski', value: 'RollerSki' },
{ name: 'Rowing', value: 'Rowing' },
{ name: 'Run', value: 'Run' },
{ name: 'Sail', value: 'Sail' },
{ name: 'Skateboard', value: 'Skateboard' },
{ name: 'Snowboard', value: 'Snowboard' },
{ name: 'Snowshoe', value: 'Snowshoe' },
{ name: 'Soccer', value: 'Soccer' },
{ name: 'Squash', value: 'Squash' },
{ name: 'Stair Stepper', value: 'StairStepper' },
{ name: 'Stand Up Paddling', value: 'StandUpPaddling' },
{ name: 'Surfing', value: 'Surfing' },
{ name: 'Swim', value: 'Swim' },
{ name: 'Table Tennis', value: 'TableTennis' },
{ name: 'Tennis', value: 'Tennis' },
{ name: 'Trail Run', value: 'TrailRun' },
{ name: 'Velomobile', value: 'Velomobile' },
{ name: 'Virtual Ride', value: 'VirtualRide' },
{ name: 'Virtual Row', value: 'VirtualRow' },
{ name: 'Virtual Run', value: 'VirtualRun' },
{ name: 'Walk', value: 'Walk' },
{ name: 'Weight Training', value: 'WeightTraining' },
{ name: 'Wheelchair', value: 'Wheelchair' },
{ name: 'Windsurf', value: 'Windsurf' },
{ name: 'Workout', value: 'Workout' },
{ name: 'Yoga', value: 'Yoga' },
],
default: 'Run',
description: 'Type of sport',
displayOptions: {
hide: {
'@version': [1],
},
},
},
{
displayName: 'Trainer',

View file

@ -17,7 +17,7 @@ export class Strava implements INodeType {
name: 'strava',
icon: 'file:strava.svg',
group: ['input'],
version: 1,
version: [1, 1.1],
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Strava API',
defaults: {
@ -56,6 +56,7 @@ export class Strava implements INodeType {
const length = items.length;
const qs: IDataObject = {};
let responseData;
const nodeVersion = this.getNode().typeVersion;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
for (let i = 0; i < length; i++) {
@ -65,8 +66,6 @@ export class Strava implements INodeType {
if (operation === 'create') {
const name = this.getNodeParameter('name', i) as string;
const type = this.getNodeParameter('type', i) as string;
const startDate = this.getNodeParameter('startDate', i) as string;
const elapsedTime = this.getNodeParameter('elapsedTime', i) as number;
@ -83,11 +82,18 @@ export class Strava implements INodeType {
const body: IDataObject = {
name,
type,
start_date_local: moment(startDate).toISOString(),
elapsed_time: elapsedTime,
};
if (nodeVersion === 1) {
const type = this.getNodeParameter('type', i) as string;
body.type = type;
} else {
const sportType = this.getNodeParameter('sport_type', i) as string;
body.sport_type = sportType;
}
Object.assign(body, additionalFields);
responseData = await stravaApiRequest.call(this, 'POST', '/activities', body);