fitbit-api-handler
Advanced tools
Comparing version 2.0.0 to 2.1.0-beta.1
@@ -5,2 +5,6 @@ # Change Log | ||
## [2.1.0-beta.1] 2018-12-22 | ||
### Changed | ||
- Use fitness models dependency for Activity model. | ||
## [2.0.0] - 2018-11-17 | ||
@@ -7,0 +11,0 @@ ### Changed |
import { Api as ApiBase, ApiResponseType } from 'rest-api-handler'; | ||
import { DateTime } from 'luxon'; | ||
import { Activity } from '../models'; | ||
import { IntradayResource, ApiToken, ActivityFilters, Scope, SubscriptionCollection, DateFilters } from '../types'; | ||
import { IntradayResource, ApiToken, ActivityFilters, ApiActivity, Scope, SubscriptionCollection, DateFilters } from '../types'; | ||
declare type ResponseType = 'code' | 'token'; | ||
@@ -17,3 +17,3 @@ declare type Prompt = 'consent' | 'login' | 'login consent' | 'none'; | ||
export declare type ActivityResponse = { | ||
activities: Array<Activity>; | ||
activities: Array<Activity<number, ApiActivity>>; | ||
pagination: Pagination; | ||
@@ -95,4 +95,4 @@ }; | ||
getAccessToken(): string | null; | ||
getLoginUrl(redirectUri: string, scope: Array<Scope>, { responseType, prompt, expiresIn, state, }: { | ||
responseType: ResponseType; | ||
getLoginUrl(redirectUri: string, scope: Array<Scope>, { responseType, prompt, expiresIn, state, }?: { | ||
responseType?: ResponseType; | ||
prompt?: Prompt; | ||
@@ -105,3 +105,3 @@ expiresIn?: number; | ||
extendAccessToken(token: string, expiresIn?: number): Promise<ApiToken>; | ||
private getApiUrl; | ||
getApiUrl(namespace: string, userId?: string, version?: string, file?: string): string; | ||
getIntradayData(resource: IntradayResource, from: DateTime, to?: DateTime, detail?: DetailLevel): Promise<IntradayResponse>; | ||
@@ -111,6 +111,6 @@ getActivitySummary(date: DateTime | string, userId?: string): Promise<ActivitySummaryResponse>; | ||
getSleeps(filters: DateFilters): Promise<SleepProcessedResponse>; | ||
getActivity(activityId: number): Promise<Activity>; | ||
getActivity(activityId: number): Promise<Activity<number, ApiActivity>>; | ||
getActivities(filters: ActivityFilters): Promise<ActivityResponse>; | ||
getActivitiesBetweenDates(from: DateTime, to: DateTime): Promise<ActivityResponse>; | ||
processActivities(filter: ActivityFilters, processor: (activity: Activity) => Promise<Activity>): Promise<Array<Activity>>; | ||
processActivities(filter: ActivityFilters, processor: (activity: Activity<number, ApiActivity>) => Promise<Activity>): Promise<Array<Activity>>; | ||
/** | ||
@@ -122,3 +122,3 @@ * https://dev.fitbit.com/build/reference/web-api/activity/#activity-logging | ||
*/ | ||
logActivity(activity: Activity): Promise<Activity>; | ||
logActivity(activity: Activity): Promise<Activity<number, ApiActivity>>; | ||
requestSubscription(method: 'POST' | 'DELETE' | 'GET', collection?: SubscriptionCollection, id?: string, subscriberId?: number): Promise<Object>; | ||
@@ -125,0 +125,0 @@ /** |
@@ -5,2 +5,3 @@ import { Api, DefaultResponseProcessor } from 'rest-api-handler'; | ||
import { unit } from 'mathjs'; | ||
import { Workout } from 'fitness-models'; | ||
@@ -66,3 +67,3 @@ function _defineProperty(obj, key, value) { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -80,33 +81,12 @@ | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -118,13 +98,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -148,3 +122,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -166,6 +140,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -176,4 +157,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -185,60 +167,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -258,3 +186,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -336,8 +264,11 @@ | ||
getLoginUrl(redirectUri, scope, _ref) { | ||
let _ref$responseType = _ref.responseType, | ||
responseType = _ref$responseType === void 0 ? 'code' : _ref$responseType, | ||
getLoginUrl(redirectUri, scope, _temp) { | ||
let _ref = _temp === void 0 ? { | ||
responseType: 'code' | ||
} : _temp, | ||
responseType = _ref.responseType, | ||
prompt = _ref.prompt, | ||
expiresIn = _ref.expiresIn, | ||
state = _ref.state; | ||
return `https://www.fitbit.com/oauth2/authorize${Api.convertParametersToUrl(_objectSpread({ | ||
@@ -344,0 +275,0 @@ response_type: responseType, |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var mathjs = require('mathjs'); | ||
var fitnessModels = require('fitness-models'); | ||
@@ -68,3 +69,3 @@ function _defineProperty(obj, key, value) { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -82,33 +83,12 @@ | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends fitnessModels.Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -120,13 +100,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -150,3 +124,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -168,6 +142,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -178,4 +159,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -187,60 +169,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -260,3 +188,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -338,8 +266,11 @@ | ||
getLoginUrl(redirectUri, scope, _ref) { | ||
let _ref$responseType = _ref.responseType, | ||
responseType = _ref$responseType === void 0 ? 'code' : _ref$responseType, | ||
getLoginUrl(redirectUri, scope, _temp) { | ||
let _ref = _temp === void 0 ? { | ||
responseType: 'code' | ||
} : _temp, | ||
responseType = _ref.responseType, | ||
prompt = _ref.prompt, | ||
expiresIn = _ref.expiresIn, | ||
state = _ref.state; | ||
return `https://www.fitbit.com/oauth2/authorize${restApiHandler.Api.convertParametersToUrl(_objectSpread({ | ||
@@ -346,0 +277,0 @@ response_type: responseType, |
@@ -5,2 +5,3 @@ import { Api, DefaultResponseProcessor } from 'rest-api-handler'; | ||
import { unit } from 'mathjs'; | ||
import { Workout } from 'fitness-models'; | ||
@@ -66,3 +67,3 @@ function _defineProperty(obj, key, value) { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -80,33 +81,12 @@ | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -118,13 +98,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -148,3 +122,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -166,6 +140,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -176,4 +157,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -185,60 +167,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -258,3 +186,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -336,8 +264,11 @@ | ||
getLoginUrl(redirectUri, scope, _ref) { | ||
let _ref$responseType = _ref.responseType, | ||
responseType = _ref$responseType === void 0 ? 'code' : _ref$responseType, | ||
getLoginUrl(redirectUri, scope, _temp) { | ||
let _ref = _temp === void 0 ? { | ||
responseType: 'code' | ||
} : _temp, | ||
responseType = _ref.responseType, | ||
prompt = _ref.prompt, | ||
expiresIn = _ref.expiresIn, | ||
state = _ref.state; | ||
return `https://www.fitbit.com/oauth2/authorize${Api.convertParametersToUrl(_objectSpread({ | ||
@@ -344,0 +275,0 @@ response_type: responseType, |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var mathjs = require('mathjs'); | ||
var fitnessModels = require('fitness-models'); | ||
@@ -70,3 +71,3 @@ function _defineProperty(obj, key, value) { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -84,33 +85,12 @@ | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends fitnessModels.Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -122,13 +102,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -152,3 +126,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -170,6 +144,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -180,4 +161,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -189,60 +171,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -262,3 +190,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -340,8 +268,11 @@ | ||
getLoginUrl(redirectUri, scope, _ref) { | ||
let _ref$responseType = _ref.responseType, | ||
responseType = _ref$responseType === void 0 ? 'code' : _ref$responseType, | ||
getLoginUrl(redirectUri, scope, _temp) { | ||
let _ref = _temp === void 0 ? { | ||
responseType: 'code' | ||
} : _temp, | ||
responseType = _ref.responseType, | ||
prompt = _ref.prompt, | ||
expiresIn = _ref.expiresIn, | ||
state = _ref.state; | ||
return `https://www.fitbit.com/oauth2/authorize${restApiHandler.Api.convertParametersToUrl(_objectSpread({ | ||
@@ -348,0 +279,0 @@ response_type: responseType, |
@@ -60,3 +60,3 @@ function _defineProperty(obj, key, value) { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -63,0 +63,0 @@ |
@@ -62,3 +62,3 @@ 'use strict'; | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -65,0 +65,0 @@ |
@@ -41,3 +41,3 @@ function _defineProperty(obj, key, value) { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -44,0 +44,0 @@ |
@@ -43,3 +43,3 @@ 'use strict'; | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -46,0 +46,0 @@ |
@@ -41,3 +41,3 @@ class FitbitException extends Error { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -44,0 +44,0 @@ |
@@ -45,3 +45,3 @@ 'use strict'; | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -48,0 +48,0 @@ |
@@ -5,2 +5,9 @@ import { Api } from './api'; | ||
import { Activity } from './models'; | ||
import { Scope as ScopeSource, ApiToken as ApiTokenSource, ActivityFilters as ActivityFiltersSource, ActivityType as ActivityTypeSource } from './types'; | ||
export declare namespace TYPES { | ||
type Scope = ScopeSource; | ||
type ApiToken = ApiTokenSource; | ||
type ActivityFilters = ActivityFiltersSource; | ||
type ActivityType = ActivityTypeSource; | ||
} | ||
export { Api, ACTIVITY_TYPES, INTRADAY_RESOURCES, SCOPES, SUBSCRIPTION_COLLECTIONS, FitbitException, FitbitApiException, Activity, }; |
@@ -5,2 +5,3 @@ import { Api, DefaultResponseProcessor } from 'rest-api-handler'; | ||
import { unit } from 'mathjs'; | ||
import { Workout } from 'fitness-models'; | ||
@@ -66,3 +67,3 @@ function _defineProperty(obj, key, value) { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -80,33 +81,12 @@ | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -118,13 +98,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -148,3 +122,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -166,6 +140,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -176,4 +157,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -185,60 +167,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -258,3 +186,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -336,8 +264,11 @@ | ||
getLoginUrl(redirectUri, scope, _ref) { | ||
let _ref$responseType = _ref.responseType, | ||
responseType = _ref$responseType === void 0 ? 'code' : _ref$responseType, | ||
getLoginUrl(redirectUri, scope, _temp) { | ||
let _ref = _temp === void 0 ? { | ||
responseType: 'code' | ||
} : _temp, | ||
responseType = _ref.responseType, | ||
prompt = _ref.prompt, | ||
expiresIn = _ref.expiresIn, | ||
state = _ref.state; | ||
return `https://www.fitbit.com/oauth2/authorize${Api.convertParametersToUrl(_objectSpread({ | ||
@@ -664,4 +595,2 @@ response_type: responseType, | ||
// @flow | ||
export { Api$1 as Api, activityTypes as ACTIVITY_TYPES, intradayResources as INTRADAY_RESOURCES, scopes as SCOPES, subscriptionCollections as SUBSCRIPTION_COLLECTIONS, FitbitException, FitbitApiException, Activity }; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var mathjs = require('mathjs'); | ||
var fitnessModels = require('fitness-models'); | ||
@@ -70,3 +71,3 @@ function _defineProperty(obj, key, value) { | ||
hasError(error) { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -84,33 +85,12 @@ | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends fitnessModels.Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -122,13 +102,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -152,3 +126,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -170,6 +144,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -180,4 +161,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -189,60 +171,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -262,3 +190,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -340,8 +268,11 @@ | ||
getLoginUrl(redirectUri, scope, _ref) { | ||
let _ref$responseType = _ref.responseType, | ||
responseType = _ref$responseType === void 0 ? 'code' : _ref$responseType, | ||
getLoginUrl(redirectUri, scope, _temp) { | ||
let _ref = _temp === void 0 ? { | ||
responseType: 'code' | ||
} : _temp, | ||
responseType = _ref.responseType, | ||
prompt = _ref.prompt, | ||
expiresIn = _ref.expiresIn, | ||
state = _ref.state; | ||
return `https://www.fitbit.com/oauth2/authorize${restApiHandler.Api.convertParametersToUrl(_objectSpread({ | ||
@@ -668,4 +599,2 @@ response_type: responseType, | ||
// @flow | ||
exports.Api = Api; | ||
@@ -672,0 +601,0 @@ exports.ACTIVITY_TYPES = activityTypes; |
import { DateTime, Duration } from 'luxon'; | ||
import { Unit } from 'mathjs'; | ||
import { Workout, TYPES } from 'fitness-models'; | ||
import { ApiActivity, ActivityType } from '../types'; | ||
declare type Constructing = { | ||
start: DateTime; | ||
duration: Duration; | ||
interface Constructor<Id, ApiSource> extends TYPES.WorkoutConstructor { | ||
typeId: ActivityType; | ||
id?: number; | ||
id: Id; | ||
typeName?: string; | ||
heartRateAvg?: number; | ||
calories?: number; | ||
distance?: Unit; | ||
tcxLink?: string; | ||
steps?: number; | ||
tcxLink?: string; | ||
source?: ApiActivity; | ||
}; | ||
export default class Activity { | ||
private start; | ||
private duration; | ||
private typeId; | ||
private id; | ||
private typeName; | ||
private heartRateAvg; | ||
private calories; | ||
private distance; | ||
private steps; | ||
private tcxLink; | ||
private source; | ||
constructor({ start, id, duration, typeName, typeId, heartRateAvg, calories, distance, steps, tcxLink, source, }: Constructing); | ||
static fromApi(activity: ApiActivity): Activity; | ||
static get(typeId: number, start: DateTime, duration: Duration, distance?: Unit, calories?: number): Activity; | ||
getId(): number | null; | ||
setId(id: number | null): this; | ||
getTypeId(): ActivityType; | ||
setTypeId(typeId: ActivityType): this; | ||
getTypeName(): string | null; | ||
getStart(): DateTime; | ||
setStart(start: DateTime): this; | ||
getEnd(): DateTime; | ||
getDuration(): Duration; | ||
setDuration(duration: Duration): this; | ||
getDistance(): Unit | null; | ||
setDistance(distance: Unit | null): this; | ||
getCalories(): number | null; | ||
setCalories(calories: number | null): this; | ||
getAvgHeartRate(): number | null; | ||
setAvgHeartRate(hr: number | null): this; | ||
getSource(): ApiActivity | null; | ||
getSteps(): number | null; | ||
getTcxLink(): string | null; | ||
source: ApiSource; | ||
} | ||
export default class Activity<Id extends (number | undefined) = any, ApiSource extends (ApiActivity | undefined) = any> extends Workout { | ||
protected typeId: ActivityType; | ||
protected typeName?: string; | ||
protected id?: number; | ||
protected steps?: number; | ||
protected tcxLink?: string; | ||
protected source?: ApiActivity; | ||
constructor(options: Constructor<Id, ApiSource>); | ||
static fromApi(activity: ApiActivity): Activity<number, ApiActivity>; | ||
static get(typeId: ActivityType, start: DateTime, duration: Duration, distance?: Unit, calories?: number): Activity<undefined, undefined>; | ||
protected clone(extension: Partial<Constructor<number | undefined, ApiSource>>): any; | ||
getId(): number | undefined; | ||
setId(id: number): Activity<number, ApiActivity>; | ||
setId(id: undefined): Activity<undefined, ApiActivity>; | ||
getTypeId(): number; | ||
getTypeName(): string; | ||
getSource(): import("../types/api/Activity").Activity | undefined; | ||
getSteps(): number | undefined; | ||
getTcxLink(): string | undefined; | ||
toString(): string; | ||
} | ||
export {}; |
import { DateTime, Duration } from 'luxon'; | ||
import { unit } from 'mathjs'; | ||
import { Workout } from 'fitness-models'; | ||
@@ -45,33 +46,12 @@ function _defineProperty(obj, key, value) { | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -83,13 +63,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -113,3 +87,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -131,6 +105,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -141,4 +122,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -150,60 +132,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -223,3 +151,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -226,0 +154,0 @@ |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var mathjs = require('mathjs'); | ||
var fitnessModels = require('fitness-models'); | ||
@@ -48,33 +49,12 @@ function _defineProperty(obj, key, value) { | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends fitnessModels.Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -86,13 +66,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -116,3 +90,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -134,6 +108,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -144,4 +125,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -153,60 +135,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -226,3 +154,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -229,0 +157,0 @@ |
import { DateTime, Duration } from 'luxon'; | ||
import { unit } from 'mathjs'; | ||
import { Workout } from 'fitness-models'; | ||
@@ -45,33 +46,12 @@ function _defineProperty(obj, key, value) { | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -83,13 +63,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -113,3 +87,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -131,6 +105,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -141,4 +122,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -150,60 +132,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -223,3 +151,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -226,0 +154,0 @@ |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var mathjs = require('mathjs'); | ||
var fitnessModels = require('fitness-models'); | ||
@@ -50,33 +51,12 @@ function _defineProperty(obj, key, value) { | ||
class Activity { | ||
// eslint-disable-next-line complexity | ||
constructor(_ref) { | ||
let start = _ref.start, | ||
id = _ref.id, | ||
duration = _ref.duration, | ||
typeName = _ref.typeName, | ||
typeId = _ref.typeId, | ||
heartRateAvg = _ref.heartRateAvg, | ||
calories = _ref.calories, | ||
distance = _ref.distance, | ||
steps = _ref.steps, | ||
tcxLink = _ref.tcxLink, | ||
source = _ref.source; | ||
class Activity extends fitnessModels.Workout { | ||
constructor(options) { | ||
super(options); | ||
_defineProperty(this, "start", void 0); | ||
_defineProperty(this, "duration", void 0); | ||
_defineProperty(this, "typeId", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "typeName", void 0); | ||
_defineProperty(this, "heartRateAvg", void 0); | ||
_defineProperty(this, "id", void 0); | ||
_defineProperty(this, "calories", void 0); | ||
_defineProperty(this, "distance", void 0); | ||
_defineProperty(this, "steps", void 0); | ||
@@ -88,13 +68,7 @@ | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
@@ -118,3 +92,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -136,6 +110,13 @@ steps: activity.steps, | ||
duration, | ||
distance | ||
distance, | ||
id: undefined, | ||
source: undefined | ||
}); | ||
} | ||
clone(extension) { | ||
// @ts-ignore | ||
return new Activity(_objectSpread({}, this.toObject(), extension)); | ||
} | ||
getId() { | ||
@@ -146,4 +127,5 @@ return this.id; | ||
setId(id) { | ||
this.id = id; | ||
return this; | ||
return this.clone({ | ||
id | ||
}); | ||
} | ||
@@ -155,60 +137,6 @@ | ||
setTypeId(typeId) { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
getTypeName() { | ||
return this.typeName; | ||
return this.typeName || 'unknown'; | ||
} | ||
getStart() { | ||
return this.start; | ||
} | ||
setStart(start) { | ||
this.start = start; | ||
return this; | ||
} | ||
getEnd() { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
getDuration() { | ||
return this.duration; | ||
} | ||
setDuration(duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
getDistance() { | ||
return this.distance; | ||
} | ||
setDistance(distance) { | ||
this.distance = distance; | ||
return this; | ||
} | ||
getCalories() { | ||
return this.calories; | ||
} | ||
setCalories(calories) { | ||
this.calories = calories; | ||
return this; | ||
} | ||
getAvgHeartRate() { | ||
return this.heartRateAvg; | ||
} | ||
setAvgHeartRate(hr) { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
getSource() { | ||
@@ -228,3 +156,3 @@ return this.source; | ||
const distance = this.getDistance(); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName() || 'uknown'}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
return [`Workout ${this.getId() || ''}`, `type: ${this.getTypeName()}`, `start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, `duration: ${Math.round(this.getDuration().as('minutes'))}min`].filter(item => item !== null).join('; '); | ||
} | ||
@@ -231,0 +159,0 @@ |
{ | ||
"name": "fitbit-api-handler", | ||
"version": "2.0.0", | ||
"version": "2.1.0-beta.1", | ||
"description": "Unofficial handler for Fitbit API", | ||
@@ -26,8 +26,12 @@ "main": "dist/index.js", | ||
"build": "rollup --config ./rollup.config.js", | ||
"develop": "tsc --emitDeclarationOnly false --watch", | ||
"test:all": "npm run lint && npm run tsc && npm run test", | ||
"prepublishOnly": "npm run build && npm run tsc && npm run test:build" | ||
"prepublishOnly": "npm run build && npm run tsc && npm run test:build", | ||
"release": "semantic-release" | ||
}, | ||
"devDependencies": { | ||
"@socifi/babel-config": "^0.6.0", | ||
"@socifi/eslint-config": "^2.0.1", | ||
"@socifi/browserslist-config": "^0.1.0", | ||
"@socifi/commitlint-config": "^1.0.0", | ||
"@socifi/eslint-config": "^2.5.0", | ||
"@socifi/jest-config": "^2.1.0", | ||
@@ -37,10 +41,13 @@ "@socifi/rollup-config": "^2.0.1", | ||
"@types/mathjs": "^4.4.3", | ||
"@types/query-string": "^6.1.1" | ||
"@types/query-string": "^6.1.1", | ||
"husky": "^1.2.1", | ||
"semantic-release-config-fabulator": "^1.0.3" | ||
}, | ||
"dependencies": { | ||
"fitness-models": "^0.2.0", | ||
"luxon": "^1.7.1", | ||
"mathjs": "^5.2.3", | ||
"query-string": "^6.2.0", | ||
"rest-api-handler": "^2.0.0" | ||
"rest-api-handler": "^2.1.0" | ||
} | ||
} |
@@ -37,3 +37,3 @@ /* eslint-disable max-lines */ | ||
export type ActivityResponse = { | ||
activities: Array<Activity>, | ||
activities: Array<Activity<number, ApiActivity>>, | ||
pagination: Pagination, | ||
@@ -158,3 +158,3 @@ }; | ||
{ | ||
responseType = 'code', | ||
responseType, | ||
prompt, | ||
@@ -164,7 +164,7 @@ expiresIn, | ||
}: { | ||
responseType: ResponseType, | ||
responseType?: ResponseType, | ||
prompt?: Prompt, | ||
expiresIn?: number, | ||
state?: string, | ||
}, | ||
} = { responseType: 'code' }, | ||
): string { | ||
@@ -220,3 +220,3 @@ return `https://www.fitbit.com/oauth2/authorize${ApiBase.convertParametersToUrl({ | ||
private getApiUrl(namespace: string, userId?: string, version = '1', file = 'json'): string { | ||
public getApiUrl(namespace: string, userId?: string, version = '1', file = 'json'): string { | ||
return `${version}/user/${userId || '-'}/${namespace}.${file}`; | ||
@@ -296,3 +296,3 @@ } | ||
public async getActivity(activityId: number): Promise<Activity> { | ||
public async getActivity(activityId: number): Promise<Activity<number, ApiActivity>> { | ||
const { data } = await this.get(this.getApiUrl(`activities/${activityId}`, undefined, '1.1')); | ||
@@ -328,3 +328,3 @@ return Activity.fromApi(data.activityLog); | ||
filter: ActivityFilters, | ||
processor: (activity: Activity) => Promise<Activity>, | ||
processor: (activity: Activity<number, ApiActivity>) => Promise<Activity>, | ||
): Promise<Array<Activity>> { | ||
@@ -352,3 +352,3 @@ const { activities, pagination } = await this.getActivities(filter); | ||
*/ | ||
public async logActivity(activity: Activity): Promise<Activity> { | ||
public async logActivity(activity: Activity): Promise<Activity<number, ApiActivity>> { | ||
const calories = activity.getCalories(); | ||
@@ -355,0 +355,0 @@ const distance = activity.getDistance(); |
@@ -33,3 +33,3 @@ import { ApiResponseType } from 'rest-api-handler'; | ||
public hasError(error: string): boolean { | ||
return typeof this.getErrors().find(item => item.errorType === error) === 'string'; | ||
return !!this.getErrors().find(item => item.errorType === error); | ||
} | ||
@@ -36,0 +36,0 @@ |
@@ -1,2 +0,1 @@ | ||
// @flow | ||
import { Api } from './api'; | ||
@@ -11,3 +10,16 @@ import { | ||
import { Activity } from './models'; | ||
import { | ||
Scope as ScopeSource, | ||
ApiToken as ApiTokenSource, | ||
ActivityFilters as ActivityFiltersSource, | ||
ActivityType as ActivityTypeSource, | ||
} from './types'; | ||
export declare namespace TYPES { | ||
export type Scope = ScopeSource; | ||
export type ApiToken = ApiTokenSource; | ||
export type ActivityFilters = ActivityFiltersSource; | ||
export type ActivityType = ActivityTypeSource; | ||
} | ||
export { | ||
@@ -14,0 +26,0 @@ Api, |
import { DateTime, Duration } from 'luxon'; | ||
import { unit, Unit } from 'mathjs'; | ||
import { Workout, TYPES } from 'fitness-models'; | ||
import { ApiActivity, ActivityType } from '../types'; | ||
import { FitbitException } from '../exceptions'; | ||
type Constructing = { | ||
start: DateTime, | ||
duration: Duration, | ||
interface Constructor<Id, ApiSource> extends TYPES.WorkoutConstructor { | ||
typeId: ActivityType, | ||
id?: number, | ||
id: Id, | ||
typeName?: string, | ||
heartRateAvg?: number, | ||
calories?: number, | ||
distance?: Unit, | ||
tcxLink?: string, | ||
steps?: number, | ||
tcxLink?: string, | ||
source?: ApiActivity, | ||
}; | ||
source: ApiSource, | ||
} | ||
export default class Activity { | ||
private start: DateTime; | ||
export default class Activity<Id extends (number | undefined) = any, ApiSource extends (ApiActivity | undefined) = any> extends Workout { | ||
protected typeId: ActivityType; | ||
private duration: Duration; | ||
protected typeName?: string; | ||
private typeId: ActivityType; | ||
protected id?: number; | ||
private id: number | null; | ||
protected steps?: number; | ||
private typeName: string | null; | ||
protected tcxLink?: string; | ||
private heartRateAvg: number | null; | ||
protected source?: ApiActivity; | ||
private calories: number | null; | ||
private distance: Unit | null; | ||
private steps: number | null; | ||
private tcxLink: string | null; | ||
private source: ApiActivity | null; | ||
// eslint-disable-next-line complexity | ||
public constructor({ | ||
start, | ||
id, | ||
duration, | ||
typeName, | ||
typeId, | ||
heartRateAvg, | ||
calories, | ||
distance, | ||
steps, | ||
tcxLink, | ||
source, | ||
}: Constructing) { | ||
this.start = start; | ||
this.duration = duration; | ||
this.typeId = typeId; | ||
this.id = id != null ? id : null; | ||
this.typeName = typeName != null ? typeName : null; | ||
this.heartRateAvg = heartRateAvg != null ? heartRateAvg : null; | ||
this.calories = calories != null ? calories : null; | ||
this.distance = distance != null ? distance : null; | ||
this.steps = steps != null ? steps : null; | ||
this.tcxLink = tcxLink != null ? tcxLink : null; | ||
this.source = source != null ? source : null; | ||
public constructor(options: Constructor<Id, ApiSource>) { | ||
super(options); | ||
this.typeId = options.typeId; | ||
this.id = options.id; | ||
this.steps = options.steps; | ||
this.tcxLink = options.tcxLink; | ||
this.source = options.source; | ||
} | ||
public static fromApi(activity: ApiActivity): Activity { | ||
public static fromApi(activity: ApiActivity): Activity<number, ApiActivity> { | ||
const { distance } = activity; | ||
@@ -86,3 +52,3 @@ | ||
typeId: activityId, | ||
heartRateAvg: activity.averageHeartRate, | ||
avgHeartRate: activity.averageHeartRate, | ||
calories: activity.calories, | ||
@@ -97,3 +63,9 @@ steps: activity.steps, | ||
// eslint-disable-next-line max-params | ||
public static get(typeId: number, start: DateTime, duration: Duration, distance?: Unit, calories?: number): Activity { | ||
public static get( | ||
typeId: ActivityType, | ||
start: DateTime, | ||
duration: Duration, | ||
distance?: Unit, | ||
calories?: number, | ||
): Activity<undefined, undefined> { | ||
return new Activity({ | ||
@@ -105,85 +77,44 @@ calories, | ||
distance, | ||
id: undefined, | ||
source: undefined, | ||
}); | ||
} | ||
public getId(): number | null { | ||
return this.id; | ||
protected clone(extension: Partial<Constructor<number | undefined, ApiSource>>): any { | ||
// @ts-ignore | ||
return new Activity({ | ||
...this.toObject(), | ||
...extension, | ||
}); | ||
} | ||
public setId(id: number | null): this { | ||
this.id = id; | ||
return this; | ||
public getId(): number | undefined { | ||
return this.id; | ||
} | ||
public getTypeId(): ActivityType { | ||
return this.typeId; | ||
} | ||
public setId(id: number): Activity<number, ApiActivity> | ||
public setTypeId(typeId: ActivityType): this { | ||
this.typeId = typeId; | ||
return this; | ||
} | ||
public setId(id: undefined): Activity<undefined, ApiActivity> | ||
public getTypeName(): string | null { | ||
return this.typeName; | ||
public setId(id: number | undefined) { | ||
return this.clone({ id }); | ||
} | ||
public getStart(): DateTime { | ||
return this.start; | ||
public getTypeId() { | ||
return this.typeId; | ||
} | ||
public setStart(start: DateTime): this { | ||
this.start = start; | ||
return this; | ||
public getTypeName() { | ||
return this.typeName || 'unknown'; | ||
} | ||
public getEnd(): DateTime { | ||
return this.getStart().plus(this.getDuration()); | ||
} | ||
public getDuration(): Duration { | ||
return this.duration; | ||
} | ||
public setDuration(duration: Duration): this { | ||
this.duration = duration; | ||
return this; | ||
} | ||
public getDistance(): Unit | null { | ||
return this.distance; | ||
} | ||
public setDistance(distance: Unit | null): this { | ||
this.distance = distance; | ||
return this; | ||
} | ||
public getCalories(): number | null { | ||
return this.calories; | ||
} | ||
public setCalories(calories: number | null): this { | ||
this.calories = calories; | ||
return this; | ||
} | ||
public getAvgHeartRate(): number | null { | ||
return this.heartRateAvg; | ||
} | ||
public setAvgHeartRate(hr: number | null): this { | ||
this.heartRateAvg = hr; | ||
return this; | ||
} | ||
public getSource(): ApiActivity | null { | ||
public getSource() { | ||
return this.source; | ||
} | ||
public getSteps(): number | null { | ||
public getSteps(): number | undefined { | ||
return this.steps; | ||
} | ||
public getTcxLink(): string | null { | ||
public getTcxLink(): string | undefined { | ||
return this.tcxLink; | ||
@@ -197,5 +128,5 @@ } | ||
`Workout ${this.getId() || ''}`, | ||
`type: ${this.getTypeName() || 'uknown'}`, | ||
`type: ${this.getTypeName()}`, | ||
`start: ${this.getStart().toFormat('yyyy-MM-dd HH:mm')}`, | ||
distance !== null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, | ||
distance != null ? `distance: ${Math.round(distance.toNumber('km') * 10) / 10}km` : null, | ||
`duration: ${Math.round(this.getDuration().as('minutes'))}min`, | ||
@@ -202,0 +133,0 @@ ].filter(item => item !== null).join('; '); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
106
0
172721
5
11
4792
1
+ Addedfitness-models@^0.2.0
+ Addedfitness-models@0.2.1(transitive)
+ Addedgpx-builder@2.5.0(transitive)
+ Addedxmlbuilder@13.0.2(transitive)
Updatedrest-api-handler@^2.1.0