Add JSON Endpoint for events
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user