diff --git a/backend/src/app/goals/goal.service.spec.ts b/backend/src/app/goals/goal.service.spec.ts index 410806c..8659016 100644 --- a/backend/src/app/goals/goal.service.spec.ts +++ b/backend/src/app/goals/goal.service.spec.ts @@ -8,6 +8,7 @@ import { TestConstants } from '../../../test/lib/constants'; import * as dayjs from 'dayjs'; import { FitnessData } from '../../integration/fitness/fitness.data'; import { FitnessGoal } from '../../integration/fitness/fitness.goal'; +import { MockProvider } from '../../integration/fitness/providers/mock.provider'; describe('GoalService', () => { let goalService: GoalService; @@ -73,6 +74,10 @@ describe('GoalService', () => { ], } as FitnessData); + fitnessService.getDatasourcesForUser.mockResolvedValue([ + new MockProvider(), + ]); + goalRepository.updateGoal.mockResolvedValue({ userId: TestConstants.database.users.exampleUser.id, type: 'steps', diff --git a/backend/src/app/goals/goal.service.ts b/backend/src/app/goals/goal.service.ts index 5ac16a9..eee0c41 100644 --- a/backend/src/app/goals/goal.service.ts +++ b/backend/src/app/goals/goal.service.ts @@ -24,7 +24,18 @@ export class GoalService { } public async refreshGoals(userId, existing: Goal[]): Promise { - const fitnessData = await this.fitnessService.getFitnessDataForUser(userId); + // Verify that the user has at least ony fitness service configured + const providers = await this.fitnessService.getDatasourcesForUser(userId); + + if (providers.length < 1) return []; + + let fitnessData; + try { + fitnessData = await this.fitnessService.getFitnessDataForUser(userId); + } catch (e) { + // Seems that the fitness provider is not available anymore + return []; + } if (!fitnessData) { throw new FitnessDataNotAvailable(); diff --git a/backend/src/app/streaks/streak.service.ts b/backend/src/app/streaks/streak.service.ts index 3e5cb39..a5d94e2 100644 --- a/backend/src/app/streaks/streak.service.ts +++ b/backend/src/app/streaks/streak.service.ts @@ -121,21 +121,26 @@ export class StreakService { * @param user ID of the user */ private async verifyDailyGoalsForUser(user: string) { - // Verify that the daily goals have not been met yet. - const streak = await this.getStreakOf(user); + try { + // Verify that the daily goals have not been met yet. + const streak = await this.getStreakOf(user); - if (streak.dailyGoalsReached == true) { - return; - } + if (streak.dailyGoalsReached == true) { + return; + } - const goals = await this.goalService.getGoalsForUser(user); + const goals = await this.goalService.getGoalsForUser(user); - if (goals.length > 0) { - for (const goal of goals) { - if (goal.value > goal.target) { - await this.addPoints(user, 10, true); + if (goals.length > 0) { + for (const goal of goals) { + if (goal.value > goal.target) { + await this.addPoints(user, 10, true); + } } } + } catch (e) { + // If something fails here, this should not stop the others + console.warn(e); } } diff --git a/backend/src/notification/emailNotifier.ts b/backend/src/notification/emailNotifier.ts index d6c6e11..99cbeb6 100644 --- a/backend/src/notification/emailNotifier.ts +++ b/backend/src/notification/emailNotifier.ts @@ -17,11 +17,15 @@ export class EmailNotifier implements Notifier { } async notify(user: User, title: string, content: string) { - await this.transporter.sendMail({ - from: process.env.EMAIL_USER, - to: user.email, - subject: title, - text: content, - }); + try { + await this.transporter.sendMail({ + from: process.env.EMAIL_USER, + to: user.email, + subject: title, + text: content, + }); + } catch (e) { + console.warn('Error while sending an email: ', e); + } } } diff --git a/backend/src/notification/notification.service.ts b/backend/src/notification/notification.service.ts index 93eff2d..f52c9c3 100644 --- a/backend/src/notification/notification.service.ts +++ b/backend/src/notification/notification.service.ts @@ -21,7 +21,7 @@ export class NotificationService { // only supports email notifications for now this.notifiers?.[user?.notificationMethod ?? '']?.notify( - userId, + user, title, content, );