From 1ce99796becdac0f45bf69385dbed8df27e09541 Mon Sep 17 00:00:00 2001 From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com> Date: Mon, 5 Oct 2020 13:54:38 +0200 Subject: [PATCH] feat: change service to monthlyReportNotification --- manifest.webapp | 4 ++-- src/atoms/userProfile.state.ts | 2 +- src/components/Options/ReportOptions.tsx | 10 +++++++--- src/db/userProfileData.json | 2 +- src/models/userProfile.model.ts | 2 +- ...monthlyReport.ts => monthlyReportNotification.ts} | 12 +++++++----- 6 files changed, 19 insertions(+), 13 deletions(-) rename src/targets/services/{monthlyReport.ts => monthlyReportNotification.ts} (91%) diff --git a/manifest.webapp b/manifest.webapp index 06e58b9f8..30a522b20 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -22,9 +22,9 @@ } }, "services": { - "monthlyReport": { + "monthlyReportNotification": { "type": "node", - "file": "services/monthlyReport/ecolyo.js", + "file": "services/monthlyReportNotification/ecolyo.js", "trigger": "@cron 0 0 * * * *" } }, diff --git a/src/atoms/userProfile.state.ts b/src/atoms/userProfile.state.ts index 848cb6127..ef16b1834 100644 --- a/src/atoms/userProfile.state.ts +++ b/src/atoms/userProfile.state.ts @@ -11,6 +11,6 @@ export const userProfileState = atom<UserProfile>({ haveSeenWelcomeModal: false, haveSeenOldFluidModal: false, notificationEcogesture: [], - report: false, + sendReportNotification: false, }, }) diff --git a/src/components/Options/ReportOptions.tsx b/src/components/Options/ReportOptions.tsx index 4ba49f852..493bb50c1 100644 --- a/src/components/Options/ReportOptions.tsx +++ b/src/components/Options/ReportOptions.tsx @@ -17,7 +17,7 @@ const ReportOptions: React.FC = () => { async (value: boolean) => { const userProfileService = new UserProfileService(client) await userProfileService - .updateUserProfile({ report: value }) + .updateUserProfile({ sendReportNotification: value }) .then(updatedUserProfile => { updatedUserProfile && setUserProfile(updatedUserProfile) }) @@ -46,7 +46,9 @@ const ReportOptions: React.FC = () => { value="true" onChange={handleChange} checked={ - userProfile && userProfile.report === true ? true : false + userProfile && userProfile.sendReportNotification === true + ? true + : false } ></input> <label htmlFor="monthly"> {t('PROFILE.REPORT.MONTHLY')}</label> @@ -59,7 +61,9 @@ const ReportOptions: React.FC = () => { value="false" onChange={handleChange} checked={ - userProfile && userProfile.report === false ? true : false + userProfile && userProfile.sendReportNotification === false + ? true + : false } ></input> <label htmlFor="never"> {t('PROFILE.REPORT.NEVER')}</label> diff --git a/src/db/userProfileData.json b/src/db/userProfileData.json index 6c7cc8692..d1699a220 100644 --- a/src/db/userProfileData.json +++ b/src/db/userProfileData.json @@ -6,6 +6,6 @@ "haveSeenWelcomeModal": false, "haveSeenOldFluidModal": false, "notificationEcogesture": ["0085", "0092"], - "report": false + "sendReportNotification": false } ] diff --git a/src/models/userProfile.model.ts b/src/models/userProfile.model.ts index be4994ed1..69660d77d 100644 --- a/src/models/userProfile.model.ts +++ b/src/models/userProfile.model.ts @@ -8,5 +8,5 @@ export interface UserProfile { haveSeenWelcomeModal: boolean haveSeenOldFluidModal: DateTime | false notificationEcogesture: string[] - report: boolean + sendReportNotification: boolean } diff --git a/src/targets/services/monthlyReport.ts b/src/targets/services/monthlyReportNotification.ts similarity index 91% rename from src/targets/services/monthlyReport.ts rename to src/targets/services/monthlyReportNotification.ts index adadaf71f..97e72e5f2 100644 --- a/src/targets/services/monthlyReport.ts +++ b/src/targets/services/monthlyReportNotification.ts @@ -11,16 +11,18 @@ import PerformanceIndicatorService from 'services/performanceIndicator.service' const log = logger.namespace('report') -interface MonthlyReportProps { +interface MonthlyReportNotificationProps { client: Client } -const monthlyReport = async ({ client }: MonthlyReportProps) => { +const monthlyReportNotification = async ({ + client, +}: MonthlyReportNotificationProps) => { log('info', 'Fetching user profile...') const upm = new UserProfileService(client) const userProfil = await upm.getUserProfile() - if (!userProfil || !userProfil.report) { - log('info', 'End of process - Report disabled in user profile') + if (!userProfil || !userProfil.sendReportNotification) { + log('info', 'End of process - Report Notification disabled in user profile') return } @@ -132,4 +134,4 @@ const monthlyReport = async ({ client }: MonthlyReportProps) => { } } -runService(monthlyReport) +runService(monthlyReportNotification) -- GitLab