Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
enedis_sge_konnector
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
LLLE_Project
enedis_sge_konnector
Merge requests
!9
Feat/insee code
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feat/insee code
feat/insee-code
into
main
Overview
0
Commits
15
Pipelines
5
Changes
4
Merged
Hugo SUBTIL
requested to merge
feat/insee-code
into
main
2 years ago
Overview
0
Commits
15
Pipelines
5
Changes
4
Expand
0
0
Merge request reports
Viewing commit
abb720e9
Prev
Next
Show latest version
4 files
+
49
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
abb720e9
feat(insee code): working function
· abb720e9
Bastien DUMONT
authored
2 years ago
src/requests/insee.js
+
24
−
4
Options
// @ts-check
const
{
default
:
axios
}
=
require
(
'
axios
'
)
const
{
log
}
=
require
(
'
cozy-konnector-libs
'
)
const
API_URL
=
'
https://apicarto.ign.fr/api
'
/**
* Return inseeCode given a postalCode
* @param {string} postalCode
* @return {Promise<string>} inseeCode
* @param {string} [city]
* @return {Promise<string | null>} inseeCode
*/
async
function
getInseeCode
(
postalCode
,
city
)
{
//TODO: Implement
log
(
'
info
'
,
`Query getInseeCode for postalCode
${
postalCode
}
/
${
city
}
`
)
throw
new
Error
(
'
Function not implemented.
'
)
try
{
const
response
=
await
axios
.
get
(
`
${
API_URL
}
/codes-postaux/communes/
${
postalCode
}
`
)
log
(
'
info
'
,
`Query getInseeCode for postalCode
${
postalCode
}
/
${
city
}
`
)
if
(
response
.
data
.
length
===
1
)
{
return
response
.
data
[
0
].
codeCommune
}
else
{
if
(
!
city
)
return
null
const
filteredResponse
=
response
.
data
.
filter
(
town
=>
town
.
nomCommune
.
toLowerCase
()
===
city
.
toLowerCase
()
)
return
filteredResponse
[
0
].
codeCommune
}
}
catch
(
error
)
{
return
null
}
}
module
.
exports
=
{
Loading