Add JSON Endpoint for events

This commit is contained in:
2022-12-24 15:03:37 +01:00
parent 3996e37682
commit 96f04c6de4
5 changed files with 74 additions and 0 deletions
@@ -0,0 +1,32 @@
import * as dotenv from 'dotenv';
import * as bcrypt from 'bcrypt';
import {Guid} from 'guid-typescript';
import {Event} from './event.interface';
import {NachklangCalendarDB} from '../Calendar.db';
dotenv.config();
/**
* Returns all events for the given calendar
* @param calendarId The calendar Id
*/
export const getAllEvents = async (calendarId: number): Promise<Event[]> => {
let conn = await NachklangCalendarDB.getConnection();
let eventRows: Event[] = [];
try {
const eventsQuery = 'SELECT * FROM events WHERE calendar_id = ?';
const eventsRes = await conn.query(eventsQuery, calendarId);
for(let row of eventsRes) {
eventRows.push(row);
}
return eventRows;
} catch (err) {
throw err;
} finally {
// Return connection
await conn.end();
}
};