Skip to content

Commit

Permalink
Modif Datagouv, check SQL, Readme πŸ›πŸ“„
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlaine committed Nov 25, 2024
1 parent f59c518 commit b233d59
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 60 deletions.
91 changes: 41 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,64 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
# VigiEau Admin - Backend

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Installation

```bash
$ yarn install
```
### PrΓ©-requis

## Running the app
Vous aurez besoin de [NodeJS](https://nodejs.org/) v18+ et [Yarn](https://yarnpkg.com/) pour lancer ce projet.

```bash
# development
$ yarn run start
Nous vous recommandons de regarder la [documentation de NestJS](https://nestjs.com/).

# watch mode
$ yarn run start:dev
### Variables d'environnement

# production mode
$ yarn run start:prod
```bash
cp env.example .env
```

## Test
- NODE_ENV : local / dev / prod
- PORT : Port sur lequel tournera le serveur
- OAUTH2_CLIENT : Se rΓ©fΓ©rer Γ  la documentation de [ProConnect](https://www.proconnect.gouv.fr/)
- SESSION_SECRET : Token JWT
- DATABASE : Informations pour se connecter Γ  la DB (Postgres)
- WEBSITE_URL : Site web du frontend (http://localhost:3000 en local)
- DOMAIN : Domaine sur lequel tourne le serveur (localhost en local)
- API_DATAGOUV : Informations pour se connecter Γ  Datagouv et pouvoir upload automatiquement les donnΓ©es de VigiEau
- ADMINJS : User / password pour accΓ©der au backend AdminJS
- S3 : Informations pour se connecter aux buckets S3
- MAIL : Informations pour se connecter Γ  la boite mail
- MAIL_MTE : Mail gΓ©nΓ©rique Γ  renseigner pour l'envoi de mail systΓ©matique Γ  une adresse
- DOMAIN_NAME : Domaine du frontend (localhost:3000 en local)
- PATH_TO_WRITE_FILE : Dossier pour stocker les fichiers temporaires ou le serveur peut lire / Γ©crire

### Installation des dΓ©pendances

```bash
# unit tests
$ yarn run test
yarn install
```

# e2e tests
$ yarn run test:e2e
### Lancer nuxt en mode dΓ©veloppement

# test coverage
$ yarn run test:cov
DΓ©marre le serveur sur http://localhost:3001

```bash
yarn start:dev
```

## Support
### GΓ©nΓ©rer le code de production

GΓ©nΓ¨re le code de production de l’application:

```bash
yarn build
```

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
## Contribution

## Stay in touch
Les Pull Requests sont les bienvenues. Pour des changements majeurs merci d'ouvrir auparavant une issue pour en discuter.

- Author - [Kamil MyΕ›liwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
Assurez-vous de mettre Γ  jour les tests en consΓ©quence.

## License

Nest is [MIT licensed](LICENSE).
[MIT](https://choosealicense.com/licenses/mit/)
12 changes: 9 additions & 3 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ DATABASE_NAME=regleau

WEBSITE_URL=http://localhost:3000
DOMAIN=localhost
API_SANDRE=
API_GEO=
API_DATAGOUV=
API_SANDRE=https://services.sandre.eaufrance.fr/
API_GEO=https://geo.api.gouv.fr
API_DATAGOUV=https://www.data.gouv.fr/api/1/
API_DATAGOUV_KEY=
API_DATAGOUV_DATASET=

Expand All @@ -39,4 +39,10 @@ MAIL_PASSWORD=
MAIL_HOST=
MAIL_PORT=

MAIL_MTE=

DOMAIN_NAME=

PATH_TO_WRITE_FILE=

NODE_TLS_REJECT_UNAUTHORIZED=0
5 changes: 5 additions & 0 deletions src/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { Departement } from './departement/entities/departement.entity';
import { BassinVersant } from './bassin_versant/entities/bassin_versant.entity';
import { Region } from './core/entities/region.entity';

/**
* DΓ©sactivΓ© pour l'instant car au final pas utilisΓ©
* Pour le rΓ©activer il suffit de rΓ©importer AdminModule dans AppModule
*/

const DEFAULT_ADMIN = {
email: process.env.ADMINJS_USER,
password: process.env.ADMINJS_PASSWORD,
Expand Down
2 changes: 0 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { ScheduleModule } from '@nestjs/schedule';
import { DepartementModule } from './departement/departement.module';
import { UsageModule } from './usage/usage.module';
import { ThematiqueModule } from './thematique/thematique.module';
import { AdminModule } from './admin.module';
import { ArreteRestrictionModule } from './arrete_restriction/arrete_restriction.module';
import { AppController } from './app.controller';
import { LoggerModule } from './logger/logger.module';
Expand Down Expand Up @@ -116,7 +115,6 @@ import { isArray, isObject } from './mail_templates/helpers/handlebars_helpers';
},
},
}),
AdminModule,
HealthModule,
ArreteCadreModule,
AuthModule,
Expand Down
10 changes: 5 additions & 5 deletions src/datagouv/datagouv.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class DatagouvService {
'restrictions': 'e403a885-5eaf-411d-a03e-751a9c22930d',
'pmtiles_archive': 'b0b246c3-f724-4eb2-a83a-c516e0044aa2',
'geojson_archive': '3972a125-2372-41f1-b3f5-25794f860414',
'arretes_cadre': '',
'arretes_cadre': '0732e970-c12c-4e6a-adca-5ac9dbc3fdfa',
};

constructor(private readonly httpService: HttpService,
Expand Down Expand Up @@ -209,7 +209,7 @@ export class DatagouvService {
date_debut: arrete.dateDebut,
date_fin: arrete.dateFin,
statut: arrete.statut,
departement_pilote: arrete.departementPilote?.code,
departement_pilote: arrete.departementPilote ? arrete.departementPilote.code : '',
departements: arrete.departements.map(d => d.code),
chemin_fichier: arrete.fichier ? arrete.fichier?.url : '',
zones_alerte: arrete.zonesAlerte.map(zone => {
Expand Down Expand Up @@ -316,7 +316,7 @@ export class DatagouvService {
const dateDebut = date ? date : moment();

for (let y = dateDebut.year(); y <= moment().year(); y++) {
// await this.generateMapsArchive(dateDebut, y, true);
await this.generateMapsArchive(dateDebut, y, true);
await this.generateMapsArchive(dateDebut, y, false);
}
}
Expand All @@ -331,13 +331,13 @@ export class DatagouvService {
try {
const { data } = await firstValueFrom(
this.httpService.get(
`${this.configService.get('S3_VHOST')}${this.configService.get('S3_PREFIX')}${geojsonOrPmtiles}/zones_${geojsonOrPmtiles}_${year}.zip`,
`${this.configService.get('S3_VHOST')}${this.configService.get('S3_PREFIX') ? this.configService.get('S3_PREFIX') : ''}${geojsonOrPmtiles}/zones_${geojsonOrPmtiles}_${year}.zip`,
{ responseType: 'arraybuffer' },
),
);
dataZip = data;
} catch (e) {
this.logger.error(`ARCHIVE ${this.configService.get('S3_VHOST')}${this.configService.get('S3_PREFIX')}${geojsonOrPmtiles}/zones_${geojsonOrPmtiles}_${year}.zip non accessible`, e);
this.logger.error(`ARCHIVE ${this.configService.get('S3_VHOST')}${this.configService.get('S3_PREFIX') ? this.configService.get('S3_PREFIX') : ''}${geojsonOrPmtiles}/zones_${geojsonOrPmtiles}_${year}.zip non accessible`, e);
}
const zip = dataZip ? await JSZip.loadAsync(dataZip) : new JSZip();

Expand Down
2 changes: 2 additions & 0 deletions src/zone_alerte_computed/zone_alerte_computed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ DELETE FROM zone_alerte_computed
// Au moins 1% de la surface en commun
.leftJoinAndSelect('commune', 'commune', 'commune.departement = departement.id AND ST_INTERSECTS(zone_alerte_computed.geom, commune.geom) AND ST_Area(ST_Intersection(zone_alerte_computed.geom, commune.geom)) / ST_AREA(commune.geom) > 0.001')
.where('departement.id = :id', { id: departement.id })
.andWhere('ST_IsValid(ST_TRANSFORM(zone_alerte_computed.geom, 4326))')
.andWhere('ST_IsValid(ST_TRANSFORM(commune.geom, 4326))')
.getRawMany();
const toSave = [];
zones.forEach(z => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ export class ZoneAlerteComputedHistoricService {
// Au moins 1% de la surface en commun
.leftJoinAndSelect('commune', 'commune', 'commune.departement = departement.id AND ST_INTERSECTS(zone_alerte_computed_historic.geom, commune.geom) AND ST_Area(ST_Intersection(zone_alerte_computed_historic.geom, commune.geom)) / ST_AREA(commune.geom) > 0.01')
.where('departement.id = :id', { id: departement.id })
.andWhere('ST_IsValid(ST_TRANSFORM(zone_alerte_computed_historic.geom, 4326))')
.andWhere('ST_IsValid(ST_TRANSFORM(commune.geom, 4326))')
.getRawMany();
const toSave = [];
zones.forEach(z => {
Expand Down

0 comments on commit b233d59

Please sign in to comment.