Skip to content

Commit

Permalink
[Bugfix] Bug fixes
Browse files Browse the repository at this point in the history
Fixed bug at revoke token
Fixed bug at sync physical activities from the first time
  • Loading branch information
lucasrochagit committed Feb 5, 2020
1 parent b982291 commit b1f4fb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/application/service/user.auth.data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export class UserAuthDataService implements IUserAuthDataService {
}

if (authData.fitbit && authData.fitbit.last_sync) {
this._eventBus.bus.pubFitbitLastSync({ child_id: authData.user_id, last_sync: authData.fitbit.last_sync })
this._eventBus.bus.pubFitbitLastSync({
child_id: authData.user_id,
last_sync: authData.fitbit.last_sync
})
.then(() => this._logger.info(`Last sync from ${authData.user_id} successful published!`))
.catch(err => this._logger.error(`Error at publish last sync: ${err.message}`))
}
Expand Down Expand Up @@ -94,8 +97,8 @@ export class UserAuthDataService implements IUserAuthDataService {
}

// 2. Revokes Fitbit access token.

const isRevoked: boolean = await this._fitbitAuthDataRepo.revokeToken(authData.fitbit.access_token)

// 3. Remove Fitbit authorization data from local database.
const isRemoved: boolean = await this._fitbitAuthDataRepo.removeFitbitAuthData(userId)

Expand Down
14 changes: 12 additions & 2 deletions src/infrastructure/repository/fitbit.data.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class FitbitDataRepository implements IFitbitDataRepository {
.then(() => {
this._logger.info(`Weight Measurements from ${userId} successful published!`)
this.saveResourceList(weights, userId)
.then(() => this._logger.info(`Weight logs from ${data.user_id} saved successful!`))
.then(() => this._logger.info(`Weight logs from ${userId} saved successful!`))
.catch(err => this._logger.error(`Error at save weight logs: ${err.message}`))
})
.catch(err => this._logger.error(`Error publishing weights: ${err.message}`))
Expand Down Expand Up @@ -360,7 +360,7 @@ export class FitbitDataRepository implements IFitbitDataRepository {
moment(data.last_sync).format('YYYY-MM-DD')
)
}
return this.getUserActivities(data.access_token!, 100, moment().format('YYYY-MM-DD'))
return this.getLastUserActivities(data.access_token!)
}

private async syncUserActivitiesLogs(data: FitbitAuthData, lastSync: string, resource: string): Promise<Array<any>> {
Expand Down Expand Up @@ -409,6 +409,16 @@ export class FitbitDataRepository implements IFitbitDataRepository {
})
}

private async getLastUserActivities(token: string): Promise<any> {
const now: string = moment().add(1, 'day').format('YYYY-MM-DD')
const path: string = `/activities/list.json?beforeDate=${now}&sort=desc&offset=0&limit=100`
return new Promise<any>((resolve, reject) => {
this._fitbitClientRepo.getDataFromPath(path, token)
.then(result => resolve(result.activities))
.catch(err => reject(this.fitbitClientErrorListener(err, token)))
})
}

private async getUserActivities(token: string, limit: number, afterDate: string): Promise<any> {
const path: string = `/activities/list.json?afterDate=${afterDate}&sort=desc&offset=0&limit=${limit}`
return new Promise<any>((resolve, reject) => {
Expand Down

0 comments on commit b1f4fb6

Please sign in to comment.