Skip to content

Commit

Permalink
feat(Strava Node): Update to use sport type (#9462)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
  • Loading branch information
CinGiu and Joffcom authored May 22, 2024
1 parent 62df433 commit 9da9368
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 4 deletions.
138 changes: 138 additions & 0 deletions packages/nodes-base/nodes/Strava/ActivityDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 10 additions & 4 deletions packages/nodes-base/nodes/Strava/Strava.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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++) {
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 9da9368

Please sign in to comment.