From 9da93680c28f9191eac7edc452e5123749e5c148 Mon Sep 17 00:00:00 2001 From: Giulio Cinelli Date: Wed, 22 May 2024 09:49:51 +0200 Subject: [PATCH] feat(Strava Node): Update to use sport type (#9462) Co-authored-by: Jonathan Bennetts --- .../nodes/Strava/ActivityDescription.ts | 138 ++++++++++++++++++ .../nodes-base/nodes/Strava/Strava.node.ts | 14 +- 2 files changed, 148 insertions(+), 4 deletions(-) diff --git a/packages/nodes-base/nodes/Strava/ActivityDescription.ts b/packages/nodes-base/nodes/Strava/ActivityDescription.ts index ddf7179ce45f2..4532ccebcfdcd 100644 --- a/packages/nodes-base/nodes/Strava/ActivityDescription.ts +++ b/packages/nodes-base/nodes/Strava/ActivityDescription.ts @@ -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', diff --git a/packages/nodes-base/nodes/Strava/Strava.node.ts b/packages/nodes-base/nodes/Strava/Strava.node.ts index f88c9c94dc905..f637009e0f990 100644 --- a/packages/nodes-base/nodes/Strava/Strava.node.ts +++ b/packages/nodes-base/nodes/Strava/Strava.node.ts @@ -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);