git add . is a difficult command to execute
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2022-12-25 15:43:37 +01:00
parent 83c9d090e1
commit a8f7189cb3
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE
2 changed files with 80 additions and 6 deletions

View File

@ -194,8 +194,60 @@ eventsRouter.put('/:eventId', async (req: Request, res: Response) => {
let success = await EventService.updateEvent(event); let success = await EventService.updateEvent(event);
if (success) {
res.status(200).send({'message': 'Event was successfully updated'}); res.status(200).send({'message': 'Event was successfully updated'});
} else {
res.status(500).send({'message': 'An error occurred during the update process. Please try again.'});
}
} catch (e: any) {
let errorGuid = Guid.create().toString();
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
res.status(500).send({
'status': 'PROCESSING_ERROR',
'message': 'Internal Server Error. Try again later.',
'reference': errorGuid
});
}
});
eventsRouter.delete('/:eventId', async (req: Request, res: Response) => {
try {
// Get params
let password = req.body.password;
if (!CredentialService.checkAdminPrivileges(password)) {
res.status(403).send({'message': 'Insufficient privileges.'});
return;
}
if (
req.params.eventId === undefined
) {
res.status(401).send({'message': 'Required parameters missing'});
return;
}
let event: Event = {
event_id: parseInt(req.params.eventId, 10),
calendar_id: -1,
uuid: '',
name: '',
description: '',
start_datetime: new Date(),
end_datetime: new Date(),
created_date: new Date(),
location: '',
created_by: '',
url: ''
};
let success = await EventService.deleteEvent(event);
if (success) {
res.status(200).send({'message': 'Event was successfully updated'});
} else {
res.status(500).send({'message': 'An error occurred during deletion. Please try again.'});
}
} catch (e: any) { } catch (e: any) {
let errorGuid = Guid.create().toString(); let errorGuid = Guid.create().toString();
logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); logger.error('Error handling a request: ' + e.message, {reference: errorGuid});

View File

@ -39,13 +39,15 @@ export const createEvent = async (event: Event): Promise<number> => {
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) VALUES (?,?,?,?,?,?,?,?,?) RETURNING event_id';
const eventsRes = await conn.query(eventsQuery, [event.calendar_id, eventUUID, event.name, event.description, event.start_datetime, event.end_datetime, event.location, event.created_by, event.url]); const eventsRes = await conn.execute(eventsQuery, [event.calendar_id, eventUUID, event.name, event.description, event.start_datetime, event.end_datetime, event.location, event.created_by, event.url]);
return eventsRes[0].event_id; return eventsRes[0].event_id;
} catch (err) { } catch (err) {
await conn.rollback();
throw err; throw err;
} finally { } finally {
// Return connection // Return connection
await conn.commit();
await conn.end(); await conn.end();
} }
}; };
@ -57,17 +59,37 @@ export const createEvent = async (event: Event): Promise<number> => {
export const updateEvent = async (event: Event): Promise<boolean> => { export const updateEvent = async (event: Event): Promise<boolean> => {
let conn = await NachklangCalendarDB.getConnection(); let conn = await NachklangCalendarDB.getConnection();
try { try {
let eventUUID = Guid.create().toString();
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 = ? WHERE event_id = ?';
const eventsRes = await conn.query(eventsQuery, [event.name, event.description, event.start_datetime, event.end_datetime, event.location, event.created_by, event.url, event.event_id]); const eventsRes = await conn.execute(eventsQuery, [event.name, event.description, event.start_datetime, event.end_datetime, event.location, event.created_by, event.url, event.event_id]);
console.log(eventsRes);
return eventsRes.affectedRows === 1; return eventsRes.affectedRows === 1;
} catch (err) { } catch (err) {
await conn.rollback();
throw err; throw err;
} finally { } finally {
// Return connection // Return connection
await conn.commit();
await conn.end();
}
};
/**
* Deletes the given event from the database
* @param event The event to delete
*/
export const deleteEvent = async (event: Event): Promise<boolean> => {
let conn = await NachklangCalendarDB.getConnection();
try {
const eventsQuery = 'DELETE FROM events WHERE event_id = ?';
const eventsRes = await conn.execute(eventsQuery, [event.event_id]);
return eventsRes.affectedRows === 1;
} catch (err) {
await conn.rollback();
throw err;
} finally {
// Return connection
await conn.commit();
await conn.end(); await conn.end();
} }
}; };