-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add api route for postal areas #386
Conversation
06d2369
to
4b5c11a
Compare
5ee9358
to
69aba5e
Compare
69aba5e
to
cc86730
Compare
@@ -26,6 +27,9 @@ export default async function apiConsumers({data: {dataType, jobType, data, stat | |||
case 'district': | |||
await districtConsumer(jobType, data, statusID) | |||
break | |||
case 'postalCode': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
postalCode
ou postalArea
? Dans l'envoi du job par l'api, c'est postalArea
qui est utilisé
const formatPayloadPostalAreas = async function (payload) { | ||
const postalCodeDBResponse = await getAllPostalAreas() || [] | ||
const postalCodesFromDB = new Set(postalCodeDBResponse.map(({postalCode}) => postalCode)) | ||
|
||
const {features, crs} = payload || {} | ||
|
||
const bulkOperations = features.map(({properties, geometry}) => { | ||
const postalCode = properties.cp | ||
postalCodesFromDB.delete(postalCode) | ||
if (geometry.crs === undefined) { | ||
geometry.crs = crs | ||
} | ||
|
||
return {postalCode, geometry} | ||
}) | ||
|
||
return {operations: bulkOperations, expiredPostalAreas: postalCodesFromDB} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
à mettre dans un fichier utils ?
const statusID = nanoid() | ||
|
||
await apiQueue.add( | ||
{dataType: 'postalArea', jobType: 'update', data: postalAreas, statusID}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ici on utilise postalArea
et dans le consumer, on utilise postalCode
@@ -0,0 +1,15 @@ | |||
import {PostalArea} from '../../util/sequelize.js' | |||
|
|||
export const getAllPostalAreas = () => PostalArea.findAll({attributes: ['postalCode']}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ici la fonction s'appelle getAllPostalAreas mais on ne récupère que les postalCode des getAllPostalAreas.
|
||
export const getAllPostalAreas = () => PostalArea.findAll({attributes: ['postalCode']}) | ||
|
||
export const putPostalAreas = postalAreas => PostalArea.bulkCreate(postalAreas, {updateOnDuplicate: ['geometry'], subQuery: false}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nom de fonction avec 'put' alors que l'on fait de la création.
postalCodes.map(postalCode => PostalArea.destroy({where: {postalCode}})) | ||
} | ||
|
||
export const updatePostalAreas = async ({operations, expiredPostalAreas}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peut-être trouvé un autre nom pour cette fonction aussi car on ne fait pas des updates mais des créations et suppressions.
319fe1c
to
cc86730
Compare
Cette partie a été revue avec un nouveau dev, on ferme la PR |
#364
Cette PR ajoute une route d'API permettant d'intégrer le fichier geojson de contours postaux fourni par La Poste dans la base de données postgres.