From b92fe72c80af49a6034e8802a37621614a964acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Lain=C3=A9?= Date: Tue, 19 Nov 2024 14:44:10 +0100 Subject: [PATCH] =?UTF-8?q?V1=20Ressources=20influenc=C3=A9es=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/zones/dto/zone.dto.ts | 3 +++ .../entities/zone_alerte_computed.entity.ts | 3 +++ src/zones/zones.service.ts | 27 ++++++++++--------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/zones/dto/zone.dto.ts b/src/zones/dto/zone.dto.ts index 2a31c95..c6721ca 100644 --- a/src/zones/dto/zone.dto.ts +++ b/src/zones/dto/zone.dto.ts @@ -38,6 +38,9 @@ export class ZoneDto { }) TypeZAS: string; + @ApiProperty({ example: true, description: "Cette ressource naturelle est-elle influencée / stockée ?" }) + ressourceInfluencee: boolean; + @ApiProperty({ enum: ['vigilance', 'alerte', 'alerte_renforcee', 'crise'], example: 'alerte_renforcee', diff --git a/src/zones/entities/zone_alerte_computed.entity.ts b/src/zones/entities/zone_alerte_computed.entity.ts index 5c104e9..7e1a2df 100644 --- a/src/zones/entities/zone_alerte_computed.entity.ts +++ b/src/zones/entities/zone_alerte_computed.entity.ts @@ -27,6 +27,9 @@ export class ZoneAlerteComputed extends BaseEntity { @Column({ nullable: false, length: 50 }) type: 'SOU' | 'SUP' | 'AEP'; + @Column({ default: false, nullable: false }) + ressourceInfluencee: boolean; + @Column({ default: false }) enabled: boolean; diff --git a/src/zones/zones.service.ts b/src/zones/zones.service.ts index f279a5d..b0ed8fc 100644 --- a/src/zones/zones.service.ts +++ b/src/zones/zones.service.ts @@ -1,6 +1,6 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { MoreThan, Repository } from 'typeorm'; +import { FindOneOptions, MoreThan, Repository } from 'typeorm'; import computeBbox from '@turf/bbox'; import { VigieauLogger } from '../logger/vigieau.logger'; import booleanPointInPolygon from '@turf/boolean-point-in-polygon'; @@ -36,7 +36,7 @@ export class ZonesService { private readonly dataService: DataService, private readonly communesService: CommunesService, @InjectRepository(ArreteMunicipal) - private readonly arreteMunicipalRepository: Repository,) { + private readonly arreteMunicipalRepository: Repository) { this.loadAllZones(true); } @@ -97,9 +97,9 @@ export class ZonesService { .filter(feature => booleanPointInPolygon([lon, lat], feature)) .map(feature => this.zonesIndex[feature.properties.idZone]); - const sup = zones.filter(z => z.type === 'SUP'); - const sou = zones.filter(z => z.type === 'SOU'); - const aep = zones.filter(z => z.type === 'AEP'); + const sup = zones.filter(z => !z.ressourceInfluencee && z.type === 'SUP'); + const sou = zones.filter(z => !z.ressourceInfluencee && z.type === 'SOU'); + const aep = zones.filter(z => !z.ressourceInfluencee && z.type === 'AEP'); if (sup.length <= 1 && sou.length <= 1 && aep.length <= 1) { return zones; @@ -122,9 +122,9 @@ export class ZonesService { return []; } - const sup = zones.filter(z => z.type === 'SUP'); - const sou = zones.filter(z => z.type === 'SOU'); - const aep = zones.filter(z => z.type === 'AEP'); + const sup = zones.filter(z => !z.ressourceInfluencee && z.type === 'SUP'); + const sou = zones.filter(z => !z.ressourceInfluencee && z.type === 'SOU'); + const aep = zones.filter(z => !z.ressourceInfluencee && z.type === 'AEP'); if (sup.length <= 1 && sou.length <= 1 && aep.length <= 1) { return zones; @@ -154,6 +154,7 @@ export class ZonesService { .addSelect('zone_alerte_computed.code', 'code') .addSelect('zone_alerte_computed.nom', 'nom') .addSelect('zone_alerte_computed.type', 'type') + .addSelect('zone_alerte_computed.ressourceInfluencee', 'ressourceInfluencee') .addSelect('zone_alerte_computed.niveauGravite', 'niveauGravite') .addSelect( 'ST_AsGeoJSON(ST_TRANSFORM(zone_alerte_computed.geom, 4326))', @@ -168,7 +169,7 @@ export class ZonesService { for (let i = 0; i < zonesWithRestrictions.length; i += batchSize) { this.logger.log(`LOADING ALL ZONES & COMMUNES - MAPPING RESTRICTION - BATCH ${i}`); await Promise.all(zonesWithRestrictions.slice(i, i + batchSize).map(async (zone) => { - const z = await this.zoneAlerteComputedRepository.findOne({ + const z = await this.zoneAlerteComputedRepository.findOne({ where: { id: zone.id, restriction: { @@ -229,6 +230,7 @@ export class ZonesService { code: z.code, nom: z.nom, type: z.type, + ressourceInfluencee: z.ressourceInfluencee, niveauGravite: z.niveauGravite, departement: z.restriction?.arreteRestriction?.departement?.code, arrete: { @@ -282,6 +284,7 @@ export class ZonesService { code: zone.code, nom: zone.nom, type: zone.type, + ressourceInfluencee: zone.ressourceInfluencee, niveauGravite: zone.niveauGravite, }; const bbox = computeBbox(geojson); @@ -327,15 +330,15 @@ export class ZonesService { const zonesFormated = zonesToReturn?.map(z => this.formatZone(z, profil, communeArreteMunicipal)); - if(communeArreteMunicipal?.fichier?.url) { + if (communeArreteMunicipal?.fichier?.url) { const zonesTypes = ['AEP', 'SOU', 'SUP']; zonesTypes.forEach(zoneType => { - if(zonesFormated.findIndex(z => z.type === zoneType) < 0) { + if (zonesFormated.findIndex(z => z.type === zoneType) < 0) { zonesFormated.push({ id: null, type: zoneType, arreteMunicipalCheminFichier: communeArreteMunicipal.fichier.url, - }) + }); } }); }