From 978ac90f5367848f2beb664c171881b361c25317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Wed, 13 Oct 2021 13:29:40 +0200 Subject: [PATCH] Properly removing all blockers now --- .../rapla-middleware/RaPlaMiddleware.router.ts | 4 ---- .../icalgenerator/icalgenerator.service.ts | 16 +++++++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/models/rapla-middleware/RaPlaMiddleware.router.ts b/src/models/rapla-middleware/RaPlaMiddleware.router.ts index 5b73741..f9e47b2 100644 --- a/src/models/rapla-middleware/RaPlaMiddleware.router.ts +++ b/src/models/rapla-middleware/RaPlaMiddleware.router.ts @@ -13,8 +13,6 @@ export const raPlaMiddlewareRouter = express.Router(); 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 +33,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}); diff --git a/src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts b/src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts index c4b3f77..4f30e1b 100644 --- a/src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts +++ b/src/models/rapla-middleware/icalgenerator/icalgenerator.service.ts @@ -68,10 +68,8 @@ 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 + 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); @@ -105,7 +103,14 @@ 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 { @@ -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); }