Skip to content

Commit

Permalink
Merge tag '1.5.7' into develop
Browse files Browse the repository at this point in the history
Bug fix
- Fixed the error that did not synchronize the Sleep data previous to the current date after notification from Fitbit.
  • Loading branch information
douglasrafael committed Jan 31, 2020
2 parents f59f803 + e2c0df1 commit ef05122
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 41 deletions.
87 changes: 57 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-sync-agent",
"version": "1.5.6",
"version": "1.5.7",
"description": "Service responsible for data synchronization of FitBit and CVE platform with OCARIoT platform.",
"main": "dist/server.js",
"scripts": {
Expand Down
20 changes: 10 additions & 10 deletions src/infrastructure/repository/fitbit.data.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export class FitbitDataRepository implements IFitbitDataRepository {

private syncLastFitbitUserSleep(data: FitbitAuthData, userId: string, date: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.getUserSleep(data.access_token!, 1, date)
this.getUserSleepFromInterval(data.access_token!, date, date)
.then(async sleeps => {
if (sleeps && sleeps.length) {
const resources: Array<any> = await this.filterDataAlreadySync(sleeps, ResourceDataType.SLEEP, userId)
Expand Down Expand Up @@ -552,6 +552,15 @@ export class FitbitDataRepository implements IFitbitDataRepository {
})
}

private async getUserSleepFromInterval(token: string, baseDate: string, endDate: string): Promise<any> {
const path: string = `/sleep/date/${baseDate}/${endDate}.json`
return new Promise<any>((resolve, reject) => {
this._fitbitClientRepo.getDataFromPath(path, token)
.then(result => resolve(result.sleep))
.catch(err => reject(this.fitbitClientErrorListener(err, token)))
})
}

private async getUserActivityLogs(token: string, resource: string, baseDate: string, endDate: string): Promise<any> {
return new Promise<any>((resolve, reject) => {
return this._fitbitClientRepo
Expand Down Expand Up @@ -589,15 +598,6 @@ export class FitbitDataRepository implements IFitbitDataRepository {
})
}

private async getUserSleep(token: string, limit: number, afterDate: string): Promise<any> {
const path: string = `/sleep/list.json?afterDate=${afterDate}&sort=desc&offset=0&limit=${limit}`
return new Promise<any>((resolve, reject) => {
this._fitbitClientRepo.getDataFromPath(path, token)
.then(result => resolve(result.sleep))
.catch(err => reject(this.fitbitClientErrorListener(err, token)))
})
}

private getSleepSummary(summary: any): any {
if (summary.asleep && summary.awake && summary.restless) {
return {
Expand Down

0 comments on commit ef05122

Please sign in to comment.