All checks were successful
Jenkins Production Deployment
Co-authored-by: Patrick Mueller <patrick@mueller-patrick.tech> Reviewed-on: #15 Co-authored-by: Patrick Müller <patrick@plutodev.de> Co-committed-by: Patrick Müller <patrick@plutodev.de>
74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
import * as dotenv from 'dotenv';
|
|
import {Event} from './Event.interface';
|
|
import {PartyPlanerDB} from '../PartyPlaner.db';
|
|
|
|
dotenv.config();
|
|
|
|
/**
|
|
* Returns all events of the given user
|
|
* @param useDev If the dev or prod database should be used
|
|
* @param userId The userId of the user to fetch the friends for
|
|
* @return Event[] A list of events
|
|
*/
|
|
export const getEventData = async (useDev: boolean, userId: string): Promise<Event[]> => {
|
|
let conn = PartyPlanerDB.getConnection(useDev);
|
|
try {
|
|
let eventRows = await conn.query('SELECT event_id, name, description, takes_place_date, registration_until_date, max_participants FROM events WHERE creator_id = ?', userId);
|
|
|
|
let eventsMap = new Map<string, Event>();
|
|
let eventIds: string[] = [];
|
|
|
|
for (let row of eventRows) {
|
|
eventIds.push(row.event_id);
|
|
let event = {
|
|
eventId: row.event_id,
|
|
name: row.name,
|
|
description: row.description,
|
|
takesPlaceDate: row.takes_place_date,
|
|
registrationUntilDate: row.registration_until_date,
|
|
maxParticipants: row.max_participants,
|
|
invites: [],
|
|
registrations: []
|
|
};
|
|
eventsMap.set(row.event_id, event);
|
|
}
|
|
|
|
let registrationRows = await conn.query('SELECT registration_id, name, registered_date, takes_part, comment, event_id FROM event_registration WHERE event_id IN (?)', eventIds);
|
|
|
|
for (let row of registrationRows) {
|
|
let event = eventsMap.get(row.event_id);
|
|
if (!event) continue;
|
|
event.registrations.push({
|
|
registrationId: row.registration_id,
|
|
name: row.name,
|
|
registeredDate: row.registered_date,
|
|
takesPart: row.takes_part,
|
|
comment: row.comment
|
|
});
|
|
}
|
|
|
|
let inviteRows = await conn.query('SELECT invite_id, invite_key, valid_until, already_used, invited_person_name, event_id FROM invitations WHERE event_id IN (?)', eventIds);
|
|
|
|
for (let row of inviteRows) {
|
|
let event = eventsMap.get(row.event_id);
|
|
if (!event) continue;
|
|
event.invites.push({
|
|
inviteId: row.invite_id,
|
|
inviteKey: row.invite_key,
|
|
validUntil: row.valid_until,
|
|
alreadyUsed: row.already_used,
|
|
invitedPersonName: row.invited_person_name
|
|
});
|
|
}
|
|
|
|
let eventsList: Event[] = [];
|
|
for (let event of eventsMap.values()) {
|
|
eventsList.push(event);
|
|
}
|
|
|
|
return eventsList;
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
};
|