Skip to content
Snippets Groups Projects
Commit 558c8c80 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

feat(carto): update and format lyon arrondissement display

parent 20dd7c1a
No related branches found
No related tags found
3 merge requests!247V2.1.0,!242V2.0,!161Feat/us135 add lyon arrondissement
import { Db, Cursor } from 'mongodb';
import { StructureDocument } from '../../structures/schemas/structure.schema';
import { getDb } from '../migrations-utils/db';
export const up = async () => {
const db: Db = await getDb();
const cursor: Cursor<StructureDocument> = db.collection('structures').find({});
let document: StructureDocument;
while ((document = await cursor.next())) {
const newDoc = updateStructure(document);
await db.collection('structures').updateOne({ _id: document._id }, [{ $set: newDoc }]);
}
console.log("Updated : removed 'Arrondissement' from structure's commune ");
};
export const down = async () => {
const db: Db = await getDb();
const cursor: Cursor<StructureDocument> = db.collection('structures').find({});
let document: StructureDocument;
while ((document = await cursor.next())) {
const newDoc = downgradeStructure(document);
await db.collection('structures').updateOne({ _id: document._id }, [{ $set: newDoc }]);
}
console.log("Downgraded : added 'Arrondissement' to structure's commune");
};
function updateStructure(doc: StructureDocument): StructureDocument {
if (doc?.address?.commune && doc.address.commune.startsWith('Lyon')) {
doc.address.commune = doc.address.commune.replace('er Arrondissement', 'er');
doc.address.commune = doc.address.commune.replace('ème Arrondissement', 'e');
}
return doc;
}
function downgradeStructure(doc: StructureDocument) {
if (doc?.address?.commune && doc.address.commune.startsWith('Lyon')) {
// First arrondissement
if (doc.address.commune.endsWith('er')) {
doc.address.commune = doc.address.commune + ' Arrondissement';
return doc;
}
// Other arrondissement
if (doc.address.commune.endsWith('e')) {
doc.address.commune = doc.address.commune.slice(0, -1) + 'ème Arrondissement';
return doc;
}
}
return doc;
}
import { HttpService, Injectable } from '@nestjs/common';
import { Logger } from '@nestjs/common';
import { HttpService, Injectable, Logger } from '@nestjs/common';
import { Observable } from 'rxjs';
import { AxiosResponse } from 'axios';
import { Cron, CronExpression } from '@nestjs/schedule';
......@@ -183,10 +182,10 @@ export class ApticStructuresService {
* Get Metropole new aptic structure evey week. For testing, please change the expression
*/
@Cron(CronExpression.EVERY_WEEK)
public getMetopoleMunicipality(): void {
public getMetropoleMunicipality(): void {
const req =
'https://download.data.grandlyon.com/ws/grandlyon/adr_voie_lieu.adrcomgl/all.json?maxfeatures=-1&start=1';
this.logger.log(`getMetopoleMunicipality | Request : ${req}`, '');
this.logger.log(`getMetropoleMunicipality | Request : ${req}`, '');
this.httpService.get(encodeURI(req)).subscribe(
(data) => {
const inseeArray = data.data.values.map((municipality) => {
......@@ -205,7 +204,7 @@ export class ApticStructuresService {
public getPostalCodeWithINSEE(inseeCode: string): Observable<AxiosResponse<any>> {
const req = `https://geo.api.gouv.fr/communes/${inseeCode}?fields=codesPostaux&format=json`;
this.logger.debug(`getMetopoleMunicipality | Request : ${req}`);
this.logger.debug(`getMetropoleMunicipality | Request : ${req}`);
return this.httpService.get(encodeURI(req));
}
......@@ -258,7 +257,23 @@ export class ApticStructuresService {
} else {
address.street = structure.address.main;
}
address.commune = structure.address.city;
if (structure.address.city === 'Lyon') {
const arrondissement = parseInt(structure.address.zip.slice(-2));
switch (arrondissement) {
case 0:
address.commune = structure.address.city;
break;
case 1:
address.commune = `${structure.address.city} 1er`;
break;
default:
address.commune = `${structure.address.city} ${arrondissement}e`;
break;
}
} else {
address.commune = structure.address.city;
}
return address;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment