Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change postal code calculation #369

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

FLoreauIGN
Copy link
Contributor

@FLoreauIGN FLoreauIGN commented Feb 16, 2024

Cette PR vise à améliorer le calcul des codes postaux dans la base postgres à l'aide de données fournies par La Poste :

  • Utilisation des données de la base officielle des codes postaux pour les communes mono-distribuées
  • Utilisation de contours postaux fournis par La Poste pour les communes pluri-distribuées
  • Dans le cas où aucun code postal n'est trouvé, on utilise l'ancienne méthode de calcul (fichier FIMOCT de la DGFIP)

Pour cela, cette PR ajoute :

  • La création de deux vues pour le calcul des meta (dont les codes postaux) dans postgres
  • L'utilisation de ces vues lors des exports de postgres vers mongo
  • Une nouvelle route d'API pour mettre à jour les codes postaux des districts à l'aide de la base officielle des codes postaux
    fix intégrer les données CP de datanova - migration #363

@FLoreauIGN FLoreauIGN marked this pull request as ready for review February 23, 2024 15:33
import {District} from '../../util/sequelize.js'

export const getDistrict = districtID => District.findByPk(districtID, {raw: true})

export const getDistricts = districtIDs => District.findAll({where: {id: districtIDs}, raw: true})

export const getDistrictsFromCog = cog => District.findAll({where: {meta: {insee: {cog}}}, raw: true})
export const getDistrictFromCog = cog => District.findAll({where: {meta: {insee: {cog}}}, raw: true})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const getDistrictFromCog = cog => District.findAll({where: {meta: {insee: {cog}}}, raw: true})
export const getDistrictsFromCog = cog => District.findAll({where: {meta: {insee: {cog}}}, raw: true})

export const getDistrictsFromCog = cog => District.findAll({where: {meta: {insee: {cog}}}, raw: true})
export const getDistrictFromCog = cog => District.findAll({where: {meta: {insee: {cog}}}, raw: true})

export const getDistrictsFromCog = async cogList => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const getDistrictsFromCog = async cogList => {
export const getDistrictsFromCogList = async cogList => {

@@ -189,7 +190,7 @@ app.get('/cog/:cog', analyticsMiddleware, async (req, res) => {
let response
try {
const {cog} = req.params
const districts = await getDistrictsFromCog(cog)
const districts = await getDistrictFromCog(cog)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const districts = await getDistrictFromCog(cog)
const districts = await getDistrictsFromCog(cog)

@antoineludeau
Copy link
Member

Il faudrait aussi renommer le fichier de migration de .js en .cjs

await apiQueue.add(
{dataType: 'district', jobType: 'updatePostalCode', data: postalFile, statusID},
{jobId: statusID, removeOnComplete: true}
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)
)
response = {
date: new Date(),
status: 'success',
message: `Check the status of your request : ${BAN_API_URL}/job-status/${statusID}`,
response: {statusID},
}

@antoineludeau
Copy link
Member

Note : penser à modifier la fonction "extractRelatedDistrictIDs" du fichier api-consumer.js. Comportement à discuter.

@nkokla nkokla linked an issue Feb 26, 2024 that may be closed by this pull request
// On February 2024 the postal file url is :
// https://datanova.laposte.fr/data-fair/api/v1/datasets/laposte-hexasmal/raw
const {url} = req.query
const postalFile = await fetch(url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const postalFile = await fetch(url)
const postalFileRawResponse = await fetch(url)
const postalFile = await postalFileRawResponse.text()

@@ -215,4 +216,59 @@ app.get('/cog/:cog', analyticsMiddleware, async (req, res) => {
res.send(response)
})

app.route('/codePostal', auth)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quand je test avec l'URL GET /district/codePostal, "express" considère que "codePostal" est un UUID et que je j'essaye de récupérer les infos d'un district.

@antoineludeau antoineludeau marked this pull request as draft March 12, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

intégrer les données CP de datanova - migration
2 participants