# Conflicts: # src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts
This commit is contained in:
75 files changed
+7952
-1747
No files matched your search
@@ -11,10 +11,61 @@ import * as icalgenerator from './icalgenerator/icalgenerator.service';
|
||||
*/
|
||||
export const raPlaMiddlewareRouter = express.Router();
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /rapla-middleware:
|
||||
* get:
|
||||
* summary: Retrieve the adjusted RaPla .ics file
|
||||
* description: Downloads the current .ics file from DHBW servers, removes unwanted events and returns the file.
|
||||
* Required urls can be generated on https://rapla-middleware.p4ddy.com
|
||||
* tags:
|
||||
* - rapla-middleware
|
||||
* responses:
|
||||
* 200:
|
||||
* description: The .ics file
|
||||
* 400:
|
||||
* description: Wrong parameters, see response body for detailed information
|
||||
* 500:
|
||||
* description: A server error occurred. Please try again. If this issue persists, contact the admin.
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: user
|
||||
* required: true
|
||||
* description: The user from RaPla, can be taken directly from the RaPla link
|
||||
* schema:
|
||||
* type: string
|
||||
* example: mueller
|
||||
* - in: query
|
||||
* name: file
|
||||
* required: true
|
||||
* description: The file from RaPla, can be taken directly from the RaPla link
|
||||
* schema:
|
||||
* type: string
|
||||
* example: TINF19B4
|
||||
* - in: query
|
||||
* name: blockers
|
||||
* required: false
|
||||
* description: Whether to remove blockers from the .ics file
|
||||
* schema:
|
||||
* type: boolean
|
||||
* example: 1
|
||||
* - in: query
|
||||
* name: wahl
|
||||
* required: false
|
||||
* description: The chosen elective module which is not to be filtered out
|
||||
* schema:
|
||||
* type: integer
|
||||
* example: 0
|
||||
* - in: query
|
||||
* name: pflicht
|
||||
* required: false
|
||||
* description: The chosen profile module which is not to be filtered out
|
||||
* schema:
|
||||
* type: integer
|
||||
* example: 2
|
||||
*/
|
||||
raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
logger.info('Starting transaction');
|
||||
|
||||
let user = (req.query.user ?? '').toString();
|
||||
let file = (req.query.file ?? '').toString();
|
||||
let blockers = (req.query.blockers ?? '').toString() === '1';
|
||||
@@ -35,8 +86,6 @@ raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
||||
|
||||
res.set({'Content-Disposition': 'attachment; filename=' + file + '.ics'});
|
||||
res.status(200).send(resultingFile);
|
||||
|
||||
logger.info('Stopping transaction');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
@@ -47,21 +96,3 @@ raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let electiveModules = {
|
||||
1: {name: ''},
|
||||
2: {name: ''},
|
||||
3: {name: ''},
|
||||
4: {name: ''},
|
||||
5: {name: ''},
|
||||
6: {name: ''},
|
||||
7: {name: ''}
|
||||
};
|
||||
|
||||
let profileModules = {
|
||||
1: {name: ''},
|
||||
2: {name: ''},
|
||||
3: {name: ''},
|
||||
4: {name: ''},
|
||||
5: {name: ''}
|
||||
};
|
||||
@@ -48,7 +48,7 @@ export const parseIcal = function (icalContents: string): iCalFile {
|
||||
header = headerMatch[0];
|
||||
}
|
||||
|
||||
header = header.substr(0, header.lastIndexOf('\n'));
|
||||
header = header.substr(0, header.lastIndexOf('\n') + 1);
|
||||
|
||||
let events: iCalEvent[] = [];
|
||||
let match: any;
|
||||
@@ -67,11 +67,9 @@ export const parseIcal = function (icalContents: string): iCalFile {
|
||||
};
|
||||
};
|
||||
|
||||
export const getDuration = function(event: string): number {
|
||||
let startRegex: RegExp = /DTSTART.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm; // Fix this, doesnt match \n but matching Z doesnt work all the time
|
||||
let endRegex: RegExp = /DTEND.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm; // s.o.
|
||||
|
||||
// localhost:3000/rapla-middleware?user=eisenbiegler&file=TINF19B4&blockers=0&wahl=4&pflicht=2
|
||||
export const getDuration = function (event: string): number {
|
||||
let startRegex: RegExp = /DTSTART.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm;
|
||||
let endRegex: RegExp = /DTEND.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm;
|
||||
|
||||
let startMatch = startRegex.exec(event);
|
||||
|
||||
@@ -80,7 +78,7 @@ export const getDuration = function(event: string): number {
|
||||
let startDtDay = 0;
|
||||
let startDtHour = 0;
|
||||
let startDtMinute = 0;
|
||||
if(startMatch) {
|
||||
if (startMatch) {
|
||||
startDtYear = parseInt(startMatch[1]);
|
||||
startDtMonth = parseInt(startMatch[2]);
|
||||
startDtDay = parseInt(startMatch[3]);
|
||||
@@ -94,7 +92,7 @@ export const getDuration = function(event: string): number {
|
||||
let endDtDay = 0;
|
||||
let endDtHour = 0;
|
||||
let endDtMinute = 0;
|
||||
if(endMatch) {
|
||||
if (endMatch) {
|
||||
endDtYear = parseInt(endMatch[1]);
|
||||
endDtMonth = parseInt(endMatch[2]);
|
||||
endDtDay = parseInt(endMatch[3]);
|
||||
@@ -105,15 +103,22 @@ export const getDuration = function(event: string): number {
|
||||
let startDt = new Date(startDtYear, startDtMonth - 1, startDtDay, startDtHour, startDtMinute);
|
||||
let endDt = new Date(endDtYear, endDtMonth - 1, endDtDay, endDtHour, endDtMinute);
|
||||
|
||||
return endDt.getHours() - startDt.getHours();
|
||||
}
|
||||
let hourDifference = endDt.getHours() - startDt.getHours();
|
||||
let minuteDifference = 0;
|
||||
|
||||
if (hourDifference === 0) {
|
||||
minuteDifference = endDt.getMinutes() - startDt.getMinutes();
|
||||
}
|
||||
|
||||
return hourDifference + (minuteDifference / 60);
|
||||
};
|
||||
|
||||
export const serializeIcal = function (ical: iCalFile): string {
|
||||
let resString = ical.head;
|
||||
ical.body.forEach((event) => {
|
||||
resString += event.content + '\n';
|
||||
});
|
||||
resString += 'END:VCALENDAR';
|
||||
resString += 'END:VCALENDAR\n';
|
||||
|
||||
return resString;
|
||||
};
|
||||
@@ -126,6 +131,7 @@ export const removeBlockers = function (ical: iCalFile): iCalFile {
|
||||
!event.content.includes('SUMMARY:Beginn Theorie')
|
||||
&& !event.content.includes('SUMMARY:Präsenz')
|
||||
&& event.duration < 10
|
||||
&& event.duration > 0.25
|
||||
) {
|
||||
remainingEvents.push(event);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user