From b8a68c2480139e006c4a0cb00ed7e84711d547f0 Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Sun, 14 May 2023 21:26:55 +0200 Subject: [PATCH] Add status column for events --- src/models/calendar/events/events.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/models/calendar/events/events.service.ts b/src/models/calendar/events/events.service.ts index c9ce491..62ecc71 100644 --- a/src/models/calendar/events/events.service.ts +++ b/src/models/calendar/events/events.service.ts @@ -14,7 +14,7 @@ export const getAllEvents = async (calendarId: number): Promise => { let conn = await NachklangCalendarDB.getConnection(); let eventRows: Event[] = []; try { - const eventsQuery = 'SELECT e.*, u.full_name FROM events e LEFT OUTER JOIN users u ON e.created_by_id = u.user_id WHERE calendar_id = ?'; + const eventsQuery = 'SELECT e.*, u.full_name FROM events e LEFT OUTER JOIN users u ON e.created_by_id = u.user_id WHERE calendar_id = ? AND status=\'PUBLIC\''; const eventsRes = await conn.query(eventsQuery, calendarId); for (let row of eventsRes) { @@ -52,7 +52,7 @@ export const createEvent = async (event: Event): Promise => { 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_id, url, whole_day) VALUES (?,?,?,?,?,?,?,?,?,?) RETURNING event_id'; + const eventsQuery = 'INSERT INTO events (calendar_id, uuid, name, description, start_datetime, end_datetime, location, created_by_id, url, whole_day, status) VALUES (?,?,?,?,?,?,?,?,?,?, \'PUBLIC\') RETURNING event_id'; const eventsRes = await conn.execute(eventsQuery, [event.calendarId, eventUUID, event.name, event.description, event.startDateTime, event.endDateTime, event.location, event.createdById, event.url, event.wholeDay]); return eventsRes[0].event_id; @@ -94,7 +94,7 @@ export const updateEvent = async (event: Event): Promise => { export const deleteEvent = async (event: Event): Promise => { let conn = await NachklangCalendarDB.getConnection(); try { - const eventsQuery = 'DELETE FROM events WHERE event_id = ?'; + const eventsQuery = 'UPDATE events SET status=\'DELETED\' WHERE event_id = ?'; const eventsRes = await conn.execute(eventsQuery, [event.eventId]); return eventsRes.affectedRows === 1;