Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: baignades alerte notif #454

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions api-node/src/utils/bathing_water/bathing_water.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BathingWaterNumberValueEnum,
BathingWaterStatusEnum,
} from '~/types/api/bathing_water';
import { NotificationDotColor } from '~/types/notifications';
import prisma from '~/prisma';
import { capture } from '~/third-parties/sentry';
import dayjs from 'dayjs';
Expand Down Expand Up @@ -267,11 +268,32 @@ function buildBathingWaterUrl(bathingWater: BathingWater): string {
return consultSiteUrl.toString();
}

function getBathingWaterDotColor(
code_indice_atmo: BathingWaterStatusEnum,
): NotificationDotColor | null {
switch (code_indice_atmo) {
case BathingWaterStatusEnum.GOOD:
return NotificationDotColor.GOOD;
case BathingWaterStatusEnum.AVERAGE:
return NotificationDotColor.FAIR;
case BathingWaterStatusEnum.POOR:
return NotificationDotColor.POOR;
case BathingWaterStatusEnum.PROHIBITION:
return NotificationDotColor.EXTREMELY_POOR;
case BathingWaterStatusEnum.UNRANKED_SITE:
case BathingWaterStatusEnum.OFF_SEASON:
case BathingWaterStatusEnum.NO_DATA:
default:
return null;
}
}

export {
getIdCarteForDepartment,
updateMunicipalitiesWithBathingWaterSites,
getBathingWaterSummaryValue,
getBathingWaterSiteValueDerivedFromBathingWaterRow,
getBathingWaterLatestResultDate,
buildBathingWaterUrl,
getBathingWaterDotColor,
};
22 changes: 21 additions & 1 deletion api-node/src/utils/notifications/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
getIndiceAtmoDotColor,
getIndiceAtmoStatus,
} from '~/utils/indice_atmo';
import { AlertStatusThresholdEnum } from '../alert_status';
import { AlertStatusThresholdEnum } from '~/utils/alert_status';
import { NotificationDotColor } from '~/types/notifications';
import { BathingWaterStatusEnum } from '~/types/api/bathing_water';
import { getBathingWaterSummaryValue } from '../bathing_water/bathing_water';

dayjs.extend(utc);

Expand Down Expand Up @@ -242,6 +245,23 @@ export async function sendAlertNotification(
}
}

if (indicatorSlug === 'bathing_water') {
const bathingWater = indicatorRow as BathingWater;
const isAlert =
bathingWater.current_year_grading ===
AlertStatusThresholdEnum.BATHING_WATER;
if (!isAlert) return false;
data.bathing_water = {
id: bathingWater.id,
};
const { value } = getBathingWaterSummaryValue([bathingWater]);
const bathingWaterDotColor = NotificationDotColor.EXTREMELY_POOR;
const bathingWaterText = `🐳 Eaux de baignade : ${BathingWaterStatusEnum.PROHIBITION} ${bathingWaterDotColor}`;
rawBody.push(bathingWaterText);
data.bathing_water.text = bathingWaterText;
indicatorValue = value;
}

if (indicatorValue === null) {
capture('No indicatorValue found for alert notification', {
extra: {
Expand Down
10 changes: 10 additions & 0 deletions api-node/src/utils/notifications/evening.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getIndiceAtmoDotColor,
getIndiceAtmoStatus,
} from '~/utils/indice_atmo';

dayjs.extend(utc);

export async function sendEveningNotification() {
Expand Down Expand Up @@ -247,6 +248,15 @@ export async function sendEveningNotification() {
}
}

/*
Bathing Water
*/
// We don't do bathing waters for two reasons
// 1. The data is updated at the most every week, or even sometimes less often,
// so it's not relevant to send it every morning or evening
// 2. The body of a notification has maximum 4 visible lines
// so we can't add more than 4 indicators, and we sacrifice the bathing water indicator

if (!body.length) {
capture('No indicators found for evening notification', {
extra: {
Expand Down
10 changes: 10 additions & 0 deletions api-node/src/utils/notifications/morning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getIndiceAtmoDotColor,
getIndiceAtmoStatus,
} from '~/utils/indice_atmo';

dayjs.extend(utc);

export async function sendMorningNotification() {
Expand Down Expand Up @@ -247,6 +248,15 @@ export async function sendMorningNotification() {
}
}

/*
Bathing Water
*/
// We don't do bathing waters for two reasons
// 1. The data is updated at the most every week, or even sometimes less often,
// so it's not relevant to send it every morning or evening
// 2. The body of a notification has maximum 4 visible lines
// so we can't add more than 4 indicators, and we sacrifice the bathing water indicator

if (!body.length) {
capture('No indicators found for morning notification', {
extra: {
Expand Down
Loading