Future-proof admin interface of the api, make the api fully capable of handling event status
This commit is contained in:
@@ -53,13 +53,22 @@ eventsRouter.get('/:calendar/json', async (req: Request, res: Response) => {
|
||||
|
||||
let calendarId: number = calendarNames.get(calendarName)!.id;
|
||||
|
||||
if (! await CredentialService.hasAccess(calendarName, sessionId, sessionKey, password, ip)) {
|
||||
res.status(403).send({'message': 'You do not have access to the specified calendar.'});
|
||||
return;
|
||||
let user = await UserService.checkSession(sessionId, sessionKey, ip);
|
||||
|
||||
if(user === null || !user.isActive) {
|
||||
if (! await CredentialService.hasAccess(calendarName, sessionId, sessionKey, password, ip)) {
|
||||
res.status(403).send({'message': 'You do not have access to the specified calendar.'});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Get events
|
||||
let events = await EventService.getAllEvents(calendarId);
|
||||
let events: Event[];
|
||||
|
||||
if(user.isActive) {
|
||||
events = await EventService.getAllEventsAdmin(calendarId);
|
||||
} else {
|
||||
events = await EventService.getAllEvents(calendarId);
|
||||
}
|
||||
|
||||
// Send the events back
|
||||
res.status(200).send(events);
|
||||
@@ -152,7 +161,8 @@ eventsRouter.post('/', async (req: Request, res: Response) => {
|
||||
location: req.body.location ?? '',
|
||||
createdById: user.userId ?? -1,
|
||||
url: req.body.url ?? '',
|
||||
wholeDay: req.body.wholeDay ?? false
|
||||
wholeDay: req.body.wholeDay ?? false,
|
||||
status: req.body.status ?? 'PUBLIC'
|
||||
};
|
||||
|
||||
let eventId = await EventService.createEvent(event);
|
||||
@@ -210,7 +220,8 @@ eventsRouter.put('/:eventId', async (req: Request, res: Response) => {
|
||||
createdBy: req.body.createdBy ?? '',
|
||||
createdById: user.userId ?? -1,
|
||||
url: req.body.url ?? '',
|
||||
wholeDay: req.body.wholeDay ?? false
|
||||
wholeDay: req.body.wholeDay ?? false,
|
||||
status: req.body.status ?? 'PUBLIC'
|
||||
};
|
||||
|
||||
let successRows = await EventService.updateEvent(event);
|
||||
@@ -267,7 +278,8 @@ eventsRouter.delete('/:eventId', async (req: Request, res: Response) => {
|
||||
createdBy: '',
|
||||
createdById: -1,
|
||||
url: '',
|
||||
wholeDay: false
|
||||
wholeDay: false,
|
||||
status: 'DELETED'
|
||||
};
|
||||
|
||||
let success = await EventService.deleteEvent(event);
|
||||
|
||||
Reference in New Issue
Block a user