Add iCal converter
Jenkins Production Deployment

This commit is contained in:
2022-12-24 17:44:28 +01:00
parent 96f04c6de4
commit b00a37eb17
4 changed files with 172 additions and 4 deletions
+29 -3
View File
@@ -4,7 +4,7 @@
import express, {Request, Response} from 'express';
import * as EventService from './events.service';
import {Event} from './event.interface';
import * as iCalService from './icalgenerator.service';
/**
@@ -13,13 +13,18 @@ import {Event} from './event.interface';
export const eventsRouter = express.Router();
/**
* Constants
*/
const fileNames = ['Nachklang_calendar', 'Nachklang_internal_calendar', 'Nachklang_management_calendar'];
/**
* Controller Definitions
*/
// POST users/register
eventsRouter.get('/all', async (req: Request, res: Response) => {
eventsRouter.get('/json', async (req: Request, res: Response) => {
try {
// Get request params
let calendarId: number = parseInt(req.query.calendar as string ?? '', 10);
@@ -27,10 +32,31 @@ eventsRouter.get('/all', async (req: Request, res: Response) => {
// Get events
let events = await EventService.getAllEvents(calendarId);
// Send the session details back to the user
// Send the events back
res.status(200).send(events);
} catch (e: any) {
console.log('Error handling a request: ' + e.message);
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
}
});
eventsRouter.get('/ical', async (req: Request, res: Response) => {
try {
// Get request params
let calendarId: number = parseInt(req.query.calendar as string ?? '', 10);
// Get events
let events = await EventService.getAllEvents(calendarId);
// generate file name
let fileName = fileNames[calendarId];
let file = await iCalService.convertToIcal(events);
// Send the ical file back
res.set({'Content-Disposition': 'attachment; filename=' + fileName + '.ics'});
res.status(200).send(file);
} catch (e: any) {
console.log('Error handling a request: ' + e.message);
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
}
});