Merge pull request #1640 from automatisch/rest-get-notifications
feat: Implement get notifications API endpoint
This commit is contained in:
@@ -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);
|
||||
};
|
@@ -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);
|
||||
});
|
||||
});
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user