diff --git a/packages/backend/src/controllers/api/v1/automatisch/notifications.js b/packages/backend/src/controllers/api/v1/automatisch/notifications.js new file mode 100644 index 00000000..e42d65f9 --- /dev/null +++ b/packages/backend/src/controllers/api/v1/automatisch/notifications.js @@ -0,0 +1,19 @@ +import { renderObject } from '../../../../helpers/renderer.js'; +import axios from '../../../../helpers/axios-with-proxy.js'; +import logger from '../../../../helpers/logger.js'; + +const NOTIFICATIONS_URL = + 'https://notifications.automatisch.io/notifications.json'; + +export default async (request, response) => { + let notifications = []; + + try { + const response = await axios.get(NOTIFICATIONS_URL); + notifications = response.data; + } catch (error) { + logger.error('Error fetching notifications API endpoint!', error); + } + + renderObject(response, notifications); +}; diff --git a/packages/backend/src/controllers/api/v1/automatisch/notifications.test.js b/packages/backend/src/controllers/api/v1/automatisch/notifications.test.js new file mode 100644 index 00000000..ddfdd90e --- /dev/null +++ b/packages/backend/src/controllers/api/v1/automatisch/notifications.test.js @@ -0,0 +1,9 @@ +import { describe, it } from 'vitest'; +import request from 'supertest'; +import app from '../../../../app.js'; + +describe('GET /api/v1/automatisch/notifications', () => { + it('should return Automatisch notifications', async () => { + await request(app).get('/api/v1/automatisch/notifications').expect(200); + }); +}); diff --git a/packages/backend/src/routes/api/v1/automatisch.js b/packages/backend/src/routes/api/v1/automatisch.js index 44eddc41..10f932e9 100644 --- a/packages/backend/src/routes/api/v1/automatisch.js +++ b/packages/backend/src/routes/api/v1/automatisch.js @@ -1,8 +1,10 @@ import { Router } from 'express'; import versionAction from '../../../controllers/api/v1/automatisch/version.js'; +import notificationsAction from '../../../controllers/api/v1/automatisch/notifications.js'; const router = Router(); router.get('/version', versionAction); +router.get('/notifications', notificationsAction); export default router;