API-31: Endpoint to get single rapla event details
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2021-10-01 18:04:40 +02:00
parent 899b316a12
commit a6e7c80c53
2 changed files with 79 additions and 0 deletions

View File

@ -28,3 +28,21 @@ dhbwRaPlaChangesRouter.get('/', async (req: Request, res: Response) => {
}); });
} }
}); });
dhbwRaPlaChangesRouter.get('/:id', async (req: Request, res: Response) => {
try {
let id: string = (req.params.id ?? '').toString();
let changes = await ChangeService.getEventById('TINF19B4', id);
res.status(200).send(changes);
} catch (e) {
let errorGuid = Guid.create().toString();
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
res.status(500).send({
'status': 'PROCESSING_ERROR',
'message': 'Internal Server Error. Try again later.',
'reference': errorGuid
});
}
});

View File

@ -84,3 +84,64 @@ export const getChanges = async (course: string, week: string): Promise<Event[]>
} }
} }
}; };
export const getEventById = async (course: string, id: string): Promise<Event> => {
let conn;
try {
conn = await pool.getConnection();
let rows = await conn.query('SELECT c.change_id, c.entry_id, c.change_timestamp, c.isDeleted, c.new_summary, c.new_description, c.new_start, c.new_last_modified, c.new_end, c.new_created, c.new_location, c.new_organizer, c.new_categories, e.uid FROM rapla_changes c LEFT OUTER JOIN rapla_entries e ON c.entry_id = e.entry_id WHERE e.uid = ? ORDER BY c.change_id', id);
let eventsMap = new Map();
for (let row of rows) {
let change: Change = {
change_id: row.change_id,
event_id: row.event_id,
change_timestamp: row.change_timestamp,
is_deleted: row.isDeleted,
new_summary: row.new_summary,
new_description: row.new_description,
new_start: row.new_start,
new_end: row.new_end,
new_last_modified: row.new_last_modified,
new_created: row.new_created,
new_location: row.new_location,
new_organizer: row.new_organizer,
new_categories: row.new_categories,
new_recurring: row.new_recurring
};
if (eventsMap.has(row.entry_id)) {
let event = eventsMap.get(row.entry_id);
// Only adjust these fields if the event is not deleted as otherwise they would be null
if (!row.isDeleted) {
event.latest_event_summary = row.new_summary;
event.latest_start_date = row.new_start;
}
event.changes.push(change);
eventsMap.set(row.entry_id, event);
} else {
let event: Event = {
event_id: row.event_id,
event_uid: row.uid,
latest_event_summary: row.new_summary,
latest_start_date: row.new_start,
changes: [change]
};
eventsMap.set(row.entry_id, event);
}
}
return Array.from(eventsMap.values())[0];
} catch (err) {
throw err;
} finally {
if (conn) {
conn.end();
}
}
};