Merge pull request #1640 from automatisch/rest-get-notifications

feat: Implement get notifications API endpoint
This commit is contained in:
Ömer Faruk Aydın
2024-02-23 11:28:11 +01:00
committed by GitHub
3 changed files with 30 additions and 0 deletions

View File

@@ -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);
};

View File

@@ -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);
});
});

View File

@@ -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;