#1: Add possibility to create whole-day events
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2022-12-28 12:15:01 +01:00
parent d85f9a992b
commit 93c70b0e1d
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE
4 changed files with 34 additions and 17 deletions

View File

@ -10,4 +10,5 @@ export interface Event {
location: string; location: string;
createdBy: string; createdBy: string;
url: string; url: string;
wholeDay: boolean;
} }

View File

@ -141,7 +141,8 @@ eventsRouter.post('/', async (req: Request, res: Response) => {
createdDate: new Date(), createdDate: new Date(),
location: req.body.location ?? '', location: req.body.location ?? '',
createdBy: req.body.createdBy ?? '', createdBy: req.body.createdBy ?? '',
url: req.body.url ?? '' url: req.body.url ?? '',
wholeDay: req.body.wholeDay ?? false
}; };
let eventId = await EventService.createEvent(event); let eventId = await EventService.createEvent(event);
@ -194,7 +195,8 @@ eventsRouter.put('/:eventId', async (req: Request, res: Response) => {
createdDate: new Date(), createdDate: new Date(),
location: req.body.location ?? '', location: req.body.location ?? '',
createdBy: req.body.createdBy ?? '', createdBy: req.body.createdBy ?? '',
url: req.body.url ?? '' url: req.body.url ?? '',
wholeDay: req.body.wholeDay ?? false
}; };
let successRows = await EventService.updateEvent(event); let successRows = await EventService.updateEvent(event);
@ -245,7 +247,8 @@ eventsRouter.delete('/:eventId', async (req: Request, res: Response) => {
createdDate: new Date(), createdDate: new Date(),
location: '', location: '',
createdBy: '', createdBy: '',
url: '' url: '',
wholeDay: false
}; };
let success = await EventService.deleteEvent(event); let success = await EventService.deleteEvent(event);

View File

@ -29,7 +29,8 @@ export const getAllEvents = async (calendarId: number): Promise<Event[]> => {
createdDate: row.created_date, createdDate: row.created_date,
location: row.location, location: row.location,
createdBy: row.created_by, createdBy: row.created_by,
url: row.url url: row.url,
wholeDay: row.whole_day
}); });
} }
@ -50,8 +51,8 @@ export const createEvent = async (event: Event): Promise<number> => {
let conn = await NachklangCalendarDB.getConnection(); let conn = await NachklangCalendarDB.getConnection();
try { try {
let eventUUID = Guid.create().toString(); let eventUUID = Guid.create().toString();
const eventsQuery = 'INSERT INTO events (calendar_id, uuid, name, description, start_datetime, end_datetime, location, created_by, url) VALUES (?,?,?,?,?,?,?,?,?) RETURNING event_id'; const eventsQuery = 'INSERT INTO events (calendar_id, uuid, name, description, start_datetime, end_datetime, location, created_by, url, whole_day) VALUES (?,?,?,?,?,?,?,?,?,?) RETURNING event_id';
const eventsRes = await conn.execute(eventsQuery, [event.calendarId, eventUUID, event.name, event.description, event.startDateTime, event.endDateTime, event.location, event.createdBy, event.url]); const eventsRes = await conn.execute(eventsQuery, [event.calendarId, eventUUID, event.name, event.description, event.startDateTime, event.endDateTime, event.location, event.createdBy, event.url, event.wholeDay]);
return eventsRes[0].event_id; return eventsRes[0].event_id;
} catch (err) { } catch (err) {
@ -71,8 +72,8 @@ export const createEvent = async (event: Event): Promise<number> => {
export const updateEvent = async (event: Event): Promise<number> => { export const updateEvent = async (event: Event): Promise<number> => {
let conn = await NachklangCalendarDB.getConnection(); let conn = await NachklangCalendarDB.getConnection();
try { try {
const eventsQuery = 'UPDATE events SET name = ?, description = ?, start_datetime = ?, end_datetime = ?, location = ?, created_by = ?, url = ? WHERE event_id = ?'; const eventsQuery = 'UPDATE events SET name = ?, description = ?, start_datetime = ?, end_datetime = ?, location = ?, created_by = ?, url = ?, whole_day = ? WHERE event_id = ?';
const eventsRes = await conn.execute(eventsQuery, [event.name, event.description, event.startDateTime, event.endDateTime, event.location, event.createdBy, event.url, event.eventId]); const eventsRes = await conn.execute(eventsQuery, [event.name, event.description, event.startDateTime, event.endDateTime, event.location, event.createdBy, event.url, event.wholeDay, event.eventId]);
return eventsRes.affectedRows; return eventsRes.affectedRows;
} catch (err) { } catch (err) {

View File

@ -34,8 +34,13 @@ const serializeIcalEvent = (icalevent: iCalEvent): string => {
returnString += 'UID:' + icalevent.uid; returnString += 'UID:' + icalevent.uid;
returnString += 'DTSTAMP:' + icalevent.created; returnString += 'DTSTAMP:' + icalevent.created;
returnString += 'ORGANIZER:' + icalevent.organizer; returnString += 'ORGANIZER:' + icalevent.organizer;
returnString += 'DTSTART;TZID=Europe/Berlin:' + icalevent.start; if(icalevent.wholeDay) {
returnString += 'DTEND;TZID=Europe/Berlin:' + icalevent.end; returnString += 'DTSTART;VALUE=DATE:' + icalevent.start;
returnString += 'DTEND;VALUE=DATE:' + icalevent.end;
} else {
returnString += 'DTSTART;TZID=Europe/Berlin:' + icalevent.start;
returnString += 'DTEND;TZID=Europe/Berlin:' + icalevent.end;
}
returnString += 'SUMMARY:' + icalevent.summary; returnString += 'SUMMARY:' + icalevent.summary;
if(!isNullOrBlank(icalevent.description)) returnString += 'DESCRIPTION:' + icalevent.description; if(!isNullOrBlank(icalevent.description)) returnString += 'DESCRIPTION:' + icalevent.description;
if(!isNullOrBlank(icalevent.location)) returnString += 'LOCATION:' + icalevent.location; if(!isNullOrBlank(icalevent.location)) returnString += 'LOCATION:' + icalevent.location;
@ -91,26 +96,32 @@ const createIcalEvent = (event: Event): iCalEvent => {
uid: event.uuid + '\n', uid: event.uuid + '\n',
created: formatDate(event.createdDate) + 'Z\n', created: formatDate(event.createdDate) + 'Z\n',
organizer: event.createdBy + '\n', organizer: event.createdBy + '\n',
start: formatDate(event.startDateTime) + '\n', start: formatDate(event.startDateTime, event.wholeDay) + '\n',
end: formatDate(event.endDateTime) + '\n', end: formatDate(event.endDateTime, event.wholeDay, true) + '\n',
summary: event.name + '\n', summary: event.name + '\n',
description: description, description: description,
location: location, location: location,
url: url, url: url,
wholeDay: event.wholeDay,
footer: 'END:VEVENT\n' footer: 'END:VEVENT\n'
}; };
}; };
const formatDate = (date: Date): string => { const formatDate = (date: Date, wholeDayFormat: boolean = false, isEndDate: boolean = false): string => {
let returnString = ''; let returnString = '';
// We need to do this for whole day events as otherwise the event ends one day too early
if(wholeDayFormat && isEndDate) date.setDate(date.getDate() + 1)
returnString += date.getFullYear(); returnString += date.getFullYear();
returnString += (date.getMonth() + 1).toString().padStart(2, '0'); // +1 Because JS sucks returnString += (date.getMonth() + 1).toString().padStart(2, '0'); // +1 Because JS sucks
returnString += date.getDate().toString().padStart(2, '0'); returnString += date.getDate().toString().padStart(2, '0');
returnString += 'T'; if(!wholeDayFormat) {
returnString += date.getHours().toString().padStart(2, '0'); returnString += 'T';
returnString += date.getMinutes().toString().padStart(2, '0'); returnString += date.getHours().toString().padStart(2, '0');
returnString += date.getSeconds().toString().padStart(2, '0'); returnString += date.getMinutes().toString().padStart(2, '0');
returnString += date.getSeconds().toString().padStart(2, '0');
}
return returnString; return returnString;
}; };
@ -132,6 +143,7 @@ export interface iCalEvent {
description: string; description: string;
location: string; location: string;
url: string; url: string;
wholeDay: boolean;
footer: string; footer: string;
} }