Skip to content

Commit 7cb1154

Browse files
committed
Ajout de niveau max par type d'eau ✨
1 parent ac9eda3 commit 7cb1154

3 files changed

Lines changed: 42 additions & 12 deletions

File tree

src/departements/departements.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,25 @@ export class DepartementsService {
136136
return {
137137
date: s.date,
138138
departementSituation: departements.map(d => {
139-
let niveauGraviteMax = s.departementSituation && s.departementSituation[d.code] ? s.departementSituation[d.code] : null;
139+
let niveauGraviteMax = s.departementSituation && s.departementSituation[d.code] ? s.departementSituation[d.code].max : null;
140+
let niveauGraviteSupMax = s.departementSituation && s.departementSituation[d.code] ? s.departementSituation[d.code].sup : null;
141+
let niveauGraviteSouMax = s.departementSituation && s.departementSituation[d.code] ? s.departementSituation[d.code].sou : null;
142+
let niveauGraviteAepMax = s.departementSituation && s.departementSituation[d.code] ? s.departementSituation[d.code].aep : null;
140143
if (s.date === new Date().toISOString().split('T')[0]) {
141144
const depZones = currentZones.filter(z => z.departement === d.code);
142145
niveauGraviteMax = depZones.length > 0 ? Utils.getNiveauInversed(max(depZones.map(z => Utils.getNiveau(z.niveauGravite)))) : null;
146+
niveauGraviteSupMax = depZones.filter(z => z.type === 'SUP').length > 0 ? Utils.getNiveauInversed(max(depZones.filter(z => z.type === 'SUP').map(z => Utils.getNiveau(z.niveauGravite)))) : null;
147+
niveauGraviteSouMax = depZones.filter(z => z.type === 'SOU').length > 0 ? Utils.getNiveauInversed(max(depZones.filter(z => z.type === 'SOU').map(z => Utils.getNiveau(z.niveauGravite)))) : null;
148+
niveauGraviteAepMax = depZones.filter(z => z.type === 'AEP').length > 0 ? Utils.getNiveauInversed(max(depZones.filter(z => z.type === 'AEP').map(z => Utils.getNiveau(z.niveauGravite)))) : null;
143149
}
144150
return {
145151
code: d.code,
146152
nom: d.nom,
147153
region: d.region?.nom,
148154
niveauGraviteMax: niveauGraviteMax,
155+
niveauGraviteSupMax: niveauGraviteSupMax,
156+
niveauGraviteSouMax: niveauGraviteSouMax,
157+
niveauGraviteAepMax: niveauGraviteAepMax,
149158
};
150159
}),
151160
};

src/departements/dto/departement.dto.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,25 @@ export class DepartementDto {
1616
description: 'Niveau de gravité maximum en vigueur sur le département, null si pas de zone d\'alerte en vigueur',
1717
})
1818
niveauGraviteMax: string;
19+
20+
@ApiProperty({
21+
enum: ['vigilance', 'alerte', 'alerte_renforcee', 'crise'],
22+
example: 'alerte_renforcee',
23+
description: 'Niveau de gravité maximum en vigueur sur le département pour les eaux de type superficielle, null si pas de zone d\'alerte en vigueur',
24+
})
25+
niveauGraviteSupMax: string;
26+
27+
@ApiProperty({
28+
enum: ['vigilance', 'alerte', 'alerte_renforcee', 'crise'],
29+
example: 'alerte_renforcee',
30+
description: 'Niveau de gravité maximum en vigueur sur le département pour les eaux de type souterraine, null si pas de zone d\'alerte en vigueur',
31+
})
32+
niveauGraviteSouMax: string;
33+
34+
@ApiProperty({
35+
enum: ['vigilance', 'alerte', 'alerte_renforcee', 'crise'],
36+
example: 'alerte_renforcee',
37+
description: 'Niveau de gravité maximum en vigueur sur le département pour les eaux potable, null si pas de zone d\'alerte en vigueur. Donnée disponible à partir du 28/04/2024.',
38+
})
39+
niveauGraviteAepMax: string;
1940
}

src/subscriptions/subscriptions.service.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,20 @@ export class SubscriptionsService {
7676
subscription.situation = {};
7777
}
7878

79+
const whereClause = subscription.commune ? {
80+
email: subscription.email,
81+
commune: subscription.commune,
82+
idAdresse: subscription.idAdresse,
83+
} : {
84+
lon: subscription.lon,
85+
lat: subscription.lat,
86+
}
7987
const subscriptionExists = await this.abonnementMailRepository.exists({
80-
where: {
81-
email: subscription.email,
82-
commune: subscription.commune,
83-
idAdresse: subscription.idAdresse,
84-
},
88+
where: whereClause,
8589
});
8690
if (subscriptionExists) {
8791
const changes = pick(subscription, 'profil', 'typesEau');
88-
await this.abonnementMailRepository.update({
89-
email: subscription.email,
90-
commune: subscription.commune,
91-
idAdresse: subscription.idAdresse,
92-
}, changes);
92+
await this.abonnementMailRepository.update(whereClause, changes);
9393
} else {
9494
await this.abonnementMailRepository.save(subscription);
9595

@@ -275,7 +275,7 @@ export class SubscriptionsService {
275275
SUP,
276276
Boolean(subscription.situation?.SUP && subscription.situation.SUP !== SUP),
277277
SOU,
278-
Boolean( subscription.situation?.SOU && subscription.situation.SOU !== SOU),
278+
Boolean(subscription.situation?.SOU && subscription.situation.SOU !== SOU),
279279
subscription.commune,
280280
subscription.libelleLocalisation,
281281
subscription.profil,

0 commit comments

Comments
 (0)