#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;
createdBy: string;
url: string;
wholeDay: boolean;
}

View File

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

View File

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

View File

@ -34,8 +34,13 @@ const serializeIcalEvent = (icalevent: iCalEvent): string => {
returnString += 'UID:' + icalevent.uid;
returnString += 'DTSTAMP:' + icalevent.created;
returnString += 'ORGANIZER:' + icalevent.organizer;
returnString += 'DTSTART;TZID=Europe/Berlin:' + icalevent.start;
returnString += 'DTEND;TZID=Europe/Berlin:' + icalevent.end;
if(icalevent.wholeDay) {
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;
if(!isNullOrBlank(icalevent.description)) returnString += 'DESCRIPTION:' + icalevent.description;
if(!isNullOrBlank(icalevent.location)) returnString += 'LOCATION:' + icalevent.location;
@ -91,26 +96,32 @@ const createIcalEvent = (event: Event): iCalEvent => {
uid: event.uuid + '\n',
created: formatDate(event.createdDate) + 'Z\n',
organizer: event.createdBy + '\n',
start: formatDate(event.startDateTime) + '\n',
end: formatDate(event.endDateTime) + '\n',
start: formatDate(event.startDateTime, event.wholeDay) + '\n',
end: formatDate(event.endDateTime, event.wholeDay, true) + '\n',
summary: event.name + '\n',
description: description,
location: location,
url: url,
wholeDay: event.wholeDay,
footer: 'END:VEVENT\n'
};
};
const formatDate = (date: Date): string => {
const formatDate = (date: Date, wholeDayFormat: boolean = false, isEndDate: boolean = false): string => {
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.getMonth() + 1).toString().padStart(2, '0'); // +1 Because JS sucks
returnString += date.getDate().toString().padStart(2, '0');
returnString += 'T';
returnString += date.getHours().toString().padStart(2, '0');
returnString += date.getMinutes().toString().padStart(2, '0');
returnString += date.getSeconds().toString().padStart(2, '0');
if(!wholeDayFormat) {
returnString += 'T';
returnString += date.getHours().toString().padStart(2, '0');
returnString += date.getMinutes().toString().padStart(2, '0');
returnString += date.getSeconds().toString().padStart(2, '0');
}
return returnString;
};
@ -132,6 +143,7 @@ export interface iCalEvent {
description: string;
location: string;
url: string;
wholeDay: boolean;
footer: string;
}