mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 18:32:41 +00:00
"Updated admin notification management: added error handling and styling, modified notification add and lookup functionality, and refactored server-side API routes and error handling."
This commit is contained in:
@@ -145,20 +145,20 @@ router.get('/admin/notification/all', async (req, res, next) => {
|
||||
try {
|
||||
const notifications = await NotificationModel.getAll();
|
||||
return res.json(notifications);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
} catch (error) {
|
||||
console.log('Error getting all notifications: ', error.message);
|
||||
return res.status(500).json({message: error.message});
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/admin/notification/add', mw.adminOnly, async (req, res, next) => {
|
||||
console.table(req.body);
|
||||
try {
|
||||
// Assuming you have some validation logic here
|
||||
const notification = await NotificationModel.addNotification(req.body);
|
||||
return res.json(notification);
|
||||
return res.status(201).json(notification);
|
||||
} catch (error) {
|
||||
console.error('Error adding notification:', error);
|
||||
return res.status(500).json({ error: 'An error occurred while adding the notification' });
|
||||
console.log('Error adding notification: ', error.message);
|
||||
return res.status(500).json({message: error.message});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -167,8 +167,8 @@ router.delete('/admin/notification/delete/:id', mw.adminOnly, async (req, res, n
|
||||
const notification = await NotificationModel.deleteNotification(req.params.id);
|
||||
return res.json(notification);
|
||||
} catch (error) {
|
||||
console.error('Error deleting notification: { key: ', req.params.id , ' error: ', error ,' }');
|
||||
return res.status(500).json({ error: 'An error occurred while deleting the notification' });
|
||||
console.error('Error deleting notification: { key: ', req.params.id , ' error: ', error.message ,' }');
|
||||
return res.status(500).json({message: error.message});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -517,7 +517,7 @@ const getPureError = (error)=>{
|
||||
|
||||
app.use(async (err, req, res, next)=>{
|
||||
err.originalUrl = req.originalUrl;
|
||||
console.error(err);
|
||||
console.error('console.log in app.js: ', err);
|
||||
|
||||
if(err.originalUrl?.startsWith('/api/')) {
|
||||
// console.log('API error');
|
||||
|
||||
Reference in New Issue
Block a user