Skip to content

Commit

Permalink
Fix : change route order to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
FLoreauIGN committed Apr 18, 2024
1 parent 8b9c5b7 commit 225cece
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions lib/api/district/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,68 @@ app.route('/')
res.send(response)
})

app.route('/codePostal', auth)
.get(async (req, res) => {
let response
try {
// 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))?.text()
const statusID = nanoid()

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

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

res.send(response)
})
.post(express.text(), async (req, res) => {
let response
try {
const postalFile = req.body
const statusID = nanoid()

await apiQueue.add(
{dataType: 'district', jobType: 'updatePostalCode', data: postalFile, statusID},
{jobId: statusID, removeOnComplete: true}
)
response = {
date: new Date(),
status: 'success',
message: `Check the status of your request : ${BAN_API_URL}/job-status/${statusID}`,
response: {statusID},
}
} catch (error) {
const {message} = error
response = {
date: new Date(),
status: 'error',
message,
response: {},
}
}

res.send(response)
})

app.route('/:districtID')
.get(analyticsMiddleware, async (req, res) => {
let response
Expand Down Expand Up @@ -220,66 +282,4 @@ app.get('/cog/:cog', analyticsMiddleware, async (req, res) => {
res.send(response)
})

app.route('/codePostal', auth)
.get(async (req, res) => {
let response
try {
// 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)
const statusID = nanoid()

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

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

res.send(response)
})
.post(express.text(), async (req, res) => {
let response
try {
const postalFile = req.body
const statusID = nanoid()

await apiQueue.add(
{dataType: 'district', jobType: 'updatePostalCode', data: postalFile, statusID},
{jobId: statusID, removeOnComplete: true}
)
response = {
date: new Date(),
status: 'success',
message: `Check the status of your request : ${BAN_API_URL}/job-status/${statusID}`,
response: {statusID},
}
} catch (error) {
const {message} = error
response = {
date: new Date(),
status: 'error',
message,
response: {},
}
}

res.send(response)
})

export default app

0 comments on commit 225cece

Please sign in to comment.