Skip to content

Commit

Permalink
Added report route for id-fix processing
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineludeau committed Jun 6, 2024
1 parent 4e4e711 commit f221636
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/api/report/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dotenv/config.js' // eslint-disable-line import/no-unassigned-import
import express from 'express'
import mongo from '../../util/mongo.cjs'
import auth from '../../middleware/auth.js'
import analyticsMiddleware from '../../middleware/analytics.js'

const app = new express.Router()

app.route('/idfix-processing')
.post(auth, analyticsMiddleware, async (req, res) => {
let response
try {
const report = req.body
const {cog} = report
if (!cog) {
throw new Error('Missing cog')
}

await mongo.db.collection('report').updateOne({cog}, {$set: report}, {upsert: true})
response = {
date: new Date(),
status: 'success',
message: 'Id-fix processing report created successfully',
response: {},
}
} catch (error) {
response = {
date: new Date(),
status: 'error',
message: error,
response: {},
}
}

res.send(response)
})

export default app
2 changes: 2 additions & 0 deletions lib/api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import commonToponymRoutes from './common-toponym/routes.js'
import districtRoutes from './district/routes.js'
import statusRoutes from './job-status/routes.js'
import banIdRoutes from './ban-id/routes.js'
import reportRoutes from './report/routes.js'

const app = new express.Router()

Expand All @@ -14,5 +15,6 @@ app.use('/common-toponym', commonToponymRoutes)
app.use('/district', districtRoutes)
app.use('/job-status', statusRoutes)
app.use('/ban-id', banIdRoutes)
app.use('/report/', reportRoutes)

export default app

0 comments on commit f221636

Please sign in to comment.