Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
Resin
Server
Commits
558c8c80
Commit
558c8c80
authored
2 years ago
by
Rémi PAILHAREY
Browse files
Options
Downloads
Patches
Plain Diff
feat(carto): update and format lyon arrondissement display
parent
20dd7c1a
No related branches found
No related tags found
3 merge requests
!247
V2.1.0
,
!242
V2.0
,
!161
Feat/us135 add lyon arrondissement
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/migrations/scripts/1653396510972-format-lyon-arrondissement.ts
+49
-0
49 additions, 0 deletions
...tions/scripts/1653396510972-format-lyon-arrondissement.ts
src/structures/services/aptic-structures.service.ts
+21
-6
21 additions, 6 deletions
src/structures/services/aptic-structures.service.ts
with
70 additions
and
6 deletions
src/migrations/scripts/1653396510972-format-lyon-arrondissement.ts
0 → 100644
+
49
−
0
View file @
558c8c80
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
;
}
This diff is collapsed.
Click to expand it.
src/structures/services/aptic-structures.service.ts
+
21
−
6
View file @
558c8c80
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
getMet
r
opoleMunicipality
():
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
(
`getMet
r
opoleMunicipality | 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
(
`getMet
r
opoleMunicipality | 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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment