-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added report route for id-fix processing
- Loading branch information
1 parent
4e4e711
commit f221636
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters