diff --git a/src/targets/services/consumptionAlert.ts b/src/targets/services/consumptionAlert.ts index 60e8320b57ad2cc1f2d103ac3d73fbac8751d313..a133d59848c591e72e2644b42381ece7af7b3a0f 100644 --- a/src/targets/services/consumptionAlert.ts +++ b/src/targets/services/consumptionAlert.ts @@ -9,7 +9,7 @@ const consumptionLimit = require('notifications/consumptionLimit.hbs') import mjml2html from 'mjml' import { FluidType } from 'enum/fluid.enum' import ConsumptionService from 'services/consumption.service' -import { getMonthName } from 'utils/utils' +import { getPreviousMonthName } from 'utils/utils' import EnvironementService from 'services/environement.service' const log = logger.namespace('alert') @@ -83,7 +83,7 @@ const consumptionAlert = async ({ client }: ConsumptionAlertProps) => { clientUrl: appLink, unsubscribeUrl: appLink + '/#/options', userLimit: userProfil.waterDailyConsumptionLimit, - limitDate: `${today.day} ${getMonthName(today)}`, + limitDate: `${today.day} ${getPreviousMonthName(today)}`, }) const mailData = { diff --git a/src/targets/services/monthlyReportNotification.ts b/src/targets/services/monthlyReportNotification.ts index c6618c104fed51e4371b85c47ee85e59434878ee..62af59c32a9ac4bc7a2ed0b2dde03330172c7c0a 100644 --- a/src/targets/services/monthlyReportNotification.ts +++ b/src/targets/services/monthlyReportNotification.ts @@ -13,7 +13,7 @@ import { TimeStep } from 'enum/timeStep.enum' import ConsumptionService from 'services/consumption.service' import { MonthlReport } from 'models/monthlyReport.model' import EnvironementService from 'services/environement.service' -import { getMonthName } from 'utils/utils' +import { getMonthNameWithPrep, getPreviousMonthName } from 'utils/utils' const log = logger.namespace('report') @@ -285,13 +285,15 @@ const monthlyReportNotification = async ({ ), pollText: monthlyReport.question.replace(/{cozyUrl}/g, appLink + '#/'), pollUrl: monthlyReport.link, - previousMonth: getMonthName(date), + previousMonth: getPreviousMonthName(date), consoImageUrl: baseUrl + '/assets/multifluidConsumption.png', }) const mailData = { mode: 'noreply', - subject: `[Ecolyo] - Votre bilan mensuel du ${date.month}-${date.year}`, + subject: `[Ecolyo] - Votre bilan mensuel du ${getMonthNameWithPrep(date)}-${ + date.year + }`, parts: [ { type: 'text/html', diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 16890bb2bb7e94a17d2e46dacea3438846c57679..21f97063f3b9b98c80a26c92931791552a280ff4 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -104,7 +104,7 @@ export const importIconbyId = async (id: string, pathType: string) => { * @param date - DateTime * @returns month in french */ -export const getMonthName = (date: DateTime) => { +export const getPreviousMonthName = (date: DateTime) => { const monthNames = [ 'janiver', 'février', @@ -122,6 +122,29 @@ export const getMonthName = (date: DateTime) => { return monthNames[date.month - 1] } +/** + * Return month string according to month index + * @param date - DateTime + * @returns month in french + */ +export const getMonthNameWithPrep = (date: DateTime) => { + const monthNames = [ + 'de janavier', + 'de février', + 'de mars', + `d'avril`, + 'de mai', + 'de juin', + 'de juillet', + `d'août`, + 'de septembre', + `d'octobre`, + 'de novembre', + 'de décembre', + ] + return monthNames[date.month] +} + /** * Return season according to following rules * - Winter is : 1/11/XXXX => 1/3/XXXX