From f221636871dcf416973bdce7d7e1a713520bc818 Mon Sep 17 00:00:00 2001 From: antoineludeau <52679050+antoineludeau@users.noreply.github.com> Date: Thu, 6 Jun 2024 15:09:26 +0200 Subject: [PATCH] Added report route for id-fix processing --- lib/api/report/routes.js | 38 ++++++++++++++++++++++++++++++++++++++ lib/api/routes.js | 2 ++ 2 files changed, 40 insertions(+) create mode 100644 lib/api/report/routes.js diff --git a/lib/api/report/routes.js b/lib/api/report/routes.js new file mode 100644 index 00000000..d55861f2 --- /dev/null +++ b/lib/api/report/routes.js @@ -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 diff --git a/lib/api/routes.js b/lib/api/routes.js index 2ac47ff5..66530530 100644 --- a/lib/api/routes.js +++ b/lib/api/routes.js @@ -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() @@ -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