@@ -38,19 +38,19 @@ eventsRouter.get('/:calendar/json', async (req: Request, res: Response) => {
|
||||
let password: string = req.query.password as string ?? '';
|
||||
|
||||
if (calendarName.length < 1) {
|
||||
res.status(401).send({'message': 'Please state the name of the calendar you want events from.'});
|
||||
res.status(400).send({'message': 'Please state the name of the calendar you want events from.'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.from(calendarNames.keys()).includes(calendarName)) {
|
||||
res.status(401).send({'message': 'Unknown calendar.'});
|
||||
res.status(400).send({'message': 'Unknown calendar.'});
|
||||
return;
|
||||
}
|
||||
|
||||
let calendarId: number = calendarNames.get(calendarName)!.id;
|
||||
|
||||
if (!CredentialService.hasAccess(calendarName, password)) {
|
||||
res.status(401).send({'message': 'You do not have access to the specified calendar.'});
|
||||
res.status(403).send({'message': 'You do not have access to the specified calendar.'});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,19 +72,19 @@ eventsRouter.get('/:calendar/ical', async (req: Request, res: Response) => {
|
||||
let password: string = req.query.password as string ?? '';
|
||||
|
||||
if (calendarName.length < 1) {
|
||||
res.status(401).send({'message': 'Please state the name of the calendar you want events from.'});
|
||||
res.status(400).send({'message': 'Please state the name of the calendar you want events from.'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.from(calendarNames.keys()).includes(calendarName)) {
|
||||
res.status(401).send({'message': 'Unknown calendar.'});
|
||||
res.status(400).send({'message': 'Unknown calendar.'});
|
||||
return;
|
||||
}
|
||||
|
||||
let calendarId: number = calendarNames.get(calendarName)!.id;
|
||||
|
||||
if (!CredentialService.hasAccess(calendarName, password)) {
|
||||
res.status(401).send({'message': 'You do not have access to the specified calendar.'});
|
||||
res.status(403).send({'message': 'You do not have access to the specified calendar.'});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,21 +125,21 @@ eventsRouter.post('/', async (req: Request, res: Response) => {
|
||||
req.body.startDateTime === undefined ||
|
||||
req.body.endDateTime === undefined
|
||||
) {
|
||||
res.status(401).send({'message': 'Required parameters missing'});
|
||||
res.status(400).send({'message': 'Required parameters missing'});
|
||||
return;
|
||||
}
|
||||
|
||||
let event: Event = {
|
||||
event_id: -1,
|
||||
calendar_id: req.body.calendarId,
|
||||
eventId: -1,
|
||||
calendarId: req.body.calendarId,
|
||||
uuid: '',
|
||||
name: req.body.name,
|
||||
description: req.body.description ?? '',
|
||||
start_datetime: new Date(req.body.startDateTime),
|
||||
end_datetime: new Date(req.body.endDateTime),
|
||||
created_date: new Date(),
|
||||
startDateTime: new Date(req.body.startDateTime),
|
||||
endDateTime: new Date(req.body.endDateTime),
|
||||
createdDate: new Date(),
|
||||
location: req.body.location ?? '',
|
||||
created_by: req.body.createdBy ?? '',
|
||||
createdBy: req.body.createdBy ?? '',
|
||||
url: req.body.url ?? ''
|
||||
};
|
||||
|
||||
@@ -174,28 +174,30 @@ eventsRouter.put('/:eventId', async (req: Request, res: Response) => {
|
||||
req.body.startDateTime === undefined ||
|
||||
req.body.endDateTime === undefined
|
||||
) {
|
||||
res.status(401).send({'message': 'Required parameters missing'});
|
||||
res.status(400).send({'message': 'Required parameters missing'});
|
||||
return;
|
||||
}
|
||||
|
||||
let event: Event = {
|
||||
event_id: parseInt(req.params.eventId, 10),
|
||||
calendar_id: req.body.calendarId,
|
||||
eventId: parseInt(req.params.eventId, 10),
|
||||
calendarId: req.body.calendarId,
|
||||
uuid: '',
|
||||
name: req.body.name,
|
||||
description: req.body.description ?? '',
|
||||
start_datetime: new Date(req.body.startDateTime),
|
||||
end_datetime: new Date(req.body.endDateTime),
|
||||
created_date: new Date(),
|
||||
startDateTime: new Date(req.body.startDateTime),
|
||||
endDateTime: new Date(req.body.endDateTime),
|
||||
createdDate: new Date(),
|
||||
location: req.body.location ?? '',
|
||||
created_by: req.body.createdBy ?? '',
|
||||
createdBy: req.body.createdBy ?? '',
|
||||
url: req.body.url ?? ''
|
||||
};
|
||||
|
||||
let success = await EventService.updateEvent(event);
|
||||
let successRows = await EventService.updateEvent(event);
|
||||
|
||||
if (success) {
|
||||
if (successRows === 1) {
|
||||
res.status(200).send({'message': 'Event was successfully updated'});
|
||||
} else if (successRows === 0) {
|
||||
res.status(200).send({'message': '0 rows were updated'});
|
||||
} else {
|
||||
res.status(500).send({'message': 'An error occurred during the update process. Please try again.'});
|
||||
}
|
||||
@@ -223,21 +225,21 @@ eventsRouter.delete('/:eventId', async (req: Request, res: Response) => {
|
||||
if (
|
||||
req.params.eventId === undefined
|
||||
) {
|
||||
res.status(401).send({'message': 'Required parameters missing'});
|
||||
res.status(400).send({'message': 'Required parameters missing'});
|
||||
return;
|
||||
}
|
||||
|
||||
let event: Event = {
|
||||
event_id: parseInt(req.params.eventId, 10),
|
||||
calendar_id: -1,
|
||||
eventId: parseInt(req.params.eventId, 10),
|
||||
calendarId: -1,
|
||||
uuid: '',
|
||||
name: '',
|
||||
description: '',
|
||||
start_datetime: new Date(),
|
||||
end_datetime: new Date(),
|
||||
created_date: new Date(),
|
||||
startDateTime: new Date(),
|
||||
endDateTime: new Date(),
|
||||
createdDate: new Date(),
|
||||
location: '',
|
||||
created_by: '',
|
||||
createdBy: '',
|
||||
url: ''
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user