From 21b0e9733be8c88a67d0c68ff0aa39803628f250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Fri, 17 Nov 2023 09:14:32 +0100 Subject: [PATCH] refactor(back): Clean code --- server/src/router.js | 4 --- server/src/routes/bso.routes.js | 53 ---------------------------- server/src/routes/openalex.routes.js | 25 ------------- 3 files changed, 82 deletions(-) delete mode 100644 server/src/routes/bso.routes.js delete mode 100644 server/src/routes/openalex.routes.js diff --git a/server/src/router.js b/server/src/router.js index 9eefa9f1..79c8d59a 100644 --- a/server/src/router.js +++ b/server/src/router.js @@ -1,13 +1,9 @@ import express from 'express'; -import bsoRouter from './routes/bso.routes'; -import openalexRouter from './routes/openalex.routes'; import worksRouter from './routes/works.routes'; const router = new express.Router(); -router.use(bsoRouter); -router.use(openalexRouter); router.use(worksRouter); export default router; diff --git a/server/src/routes/bso.routes.js b/server/src/routes/bso.routes.js deleted file mode 100644 index 0183ddeb..00000000 --- a/server/src/routes/bso.routes.js +++ /dev/null @@ -1,53 +0,0 @@ -import express from 'express'; -import fetch from 'node-fetch'; - -import { getBsoQuery, getBsoWorks } from '../utils'; - -const router = new express.Router(); - -router.route('/bso/count') - .get(async (req, res) => { - try { - const options = req?.query ?? {}; - if (!options?.affiliations) { - res.status(400).json({ message: 'You must provide at least one affiliation.' }); - } else { - const body = getBsoQuery(options); - delete body._source; - delete body.size; - delete body.sort; - let response = await fetch(`${process.env.VITE_BSO_URL}/_count`, { - method: 'POST', - body: JSON.stringify(body), - headers: { - 'content-type': 'application/json', - Authorization: process.env.VITE_BSO_AUTH, - }, - }); - response = await response.json(); - res.status(200).json(response); - } - } catch (err) { - console.error(err); - res.status(500).json({ message: 'Internal Server Error.' }); - } - }); - -router.route('/bso/works') - .get(async (req, res) => { - try { - const options = req?.query ?? {}; - const index = options?.index ?? process.env.VITE_BSO_PUBLICATIONS_INDEX; - if (!options?.affiliations) { - res.status(400).json({ message: 'You must provide at least one affiliation.' }); - } else { - const response = await getBsoWorks({ index, options }); - res.status(200).json(response); - } - } catch (err) { - console.error(err); - res.status(500).json({ message: 'Internal Server Error.' }); - } - }); - -export default router; diff --git a/server/src/routes/openalex.routes.js b/server/src/routes/openalex.routes.js deleted file mode 100644 index 70e045ef..00000000 --- a/server/src/routes/openalex.routes.js +++ /dev/null @@ -1,25 +0,0 @@ -import express from 'express'; -import fetch from 'node-fetch'; - -const router = new express.Router(); - -router.route('/openalex') - .get(async (req, res) => { - let urlParams = req?.query ?? {}; - if (process?.env?.VITE_OPENALEX_KEY) { - urlParams = { ...urlParams, api_key: process.env.VITE_OPENALEX_KEY }; - } else { - urlParams = { ...urlParams, mailto: 'bso@recherche.gouv.fr' }; - } - const url = `https://api.openalex.org/works?${new URLSearchParams(urlParams)}`; - try { - let response = await fetch(url); - response = await response.json(); - res.status(200).json(response); - } catch (err) { - console.error(err); - res.status(500).json({ message: 'Internal Server Error.' }); - } - }); - -export default router;