From 5c2ad7dfeeb055eb45e0b990b38b7b3e82f01c30 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 18 Sep 2024 15:50:46 -0400 Subject: [PATCH] More Linting --- .../notificationAdd/notificationAdd.jsx | 2 +- .../notificationLookup/notificationLookup.jsx | 6 +- .../notificationUtils/notificationUtils.jsx | 14 +- server/admin.api.js | 52 +++---- server/notifications.model.js | 132 +++++++++--------- 5 files changed, 103 insertions(+), 103 deletions(-) diff --git a/client/admin/notificationUtils/notificationAdd/notificationAdd.jsx b/client/admin/notificationUtils/notificationAdd/notificationAdd.jsx index e096a691b..fd443b30f 100644 --- a/client/admin/notificationUtils/notificationAdd/notificationAdd.jsx +++ b/client/admin/notificationUtils/notificationAdd/notificationAdd.jsx @@ -26,7 +26,7 @@ const NotificationAdd = ()=>{ setError('All fields are required'); return; } - if (startAt >= stopAt) { + if(startAt >= stopAt) { setError('End date must be after the start date!'); return; } diff --git a/client/admin/notificationUtils/notificationLookup/notificationLookup.jsx b/client/admin/notificationUtils/notificationLookup/notificationLookup.jsx index 3c129d886..9e4681136 100644 --- a/client/admin/notificationUtils/notificationLookup/notificationLookup.jsx +++ b/client/admin/notificationUtils/notificationLookup/notificationLookup.jsx @@ -45,7 +45,7 @@ const NotificationLookup = ()=>{ setNotifications(res.body || []); } catch (err) { console.log(err); - setError(`Error looking up notifications: ${err.response.body.message}`) + setError(`Error looking up notifications: ${err.response.body.message}`); } finally { setSearching(false); } @@ -71,9 +71,9 @@ const NotificationLookup = ()=>{ lookupAll(); } catch (err) { console.log(err); - setError(`Error deleting notification: ${err.response.body.message}`) + setError(`Error deleting notification: ${err.response.body.message}`); }; - } + }; const renderNotificationsList = ()=>{ if(error) diff --git a/client/admin/notificationUtils/notificationUtils.jsx b/client/admin/notificationUtils/notificationUtils.jsx index 2e2c4b634..22ea21328 100644 --- a/client/admin/notificationUtils/notificationUtils.jsx +++ b/client/admin/notificationUtils/notificationUtils.jsx @@ -3,13 +3,13 @@ const React = require('react'); const NotificationLookup = require('./notificationLookup/notificationLookup.jsx'); const NotificationAdd = require('./notificationAdd/notificationAdd.jsx'); -const NotificationUtils = () => { - return ( -
- - -
- ); +const NotificationUtils = ()=>{ + return ( +
+ + +
+ ); }; module.exports = NotificationUtils; diff --git a/server/admin.api.js b/server/admin.api.js index 4c9fa5e39..a112dc6f1 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -141,35 +141,35 @@ router.get('/admin/stats', mw.adminOnly, async (req, res)=>{ // ####################### NOTIFICATIONS -router.get('/admin/notification/all', async (req, res, next) => { +router.get('/admin/notification/all', async (req, res, next)=>{ try { const notifications = await NotificationModel.getAll(); return res.json(notifications); - } catch (error) { - console.log('Error getting all notifications: ', error.message); - return res.status(500).json({message: error.message}); - } + } 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 { - const notification = await NotificationModel.addNotification(req.body); - return res.status(201).json(notification); - } catch (error) { - console.log('Error adding notification: ', 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 { + const notification = await NotificationModel.addNotification(req.body); + return res.status(201).json(notification); + } catch (error) { + console.log('Error adding notification: ', error.message); + return res.status(500).json({ message: error.message }); + } }); -router.delete('/admin/notification/delete/:id', mw.adminOnly, async (req, res, next) => { - try { - 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.message ,' }'); - return res.status(500).json({message: error.message}); - } +router.delete('/admin/notification/delete/:id', mw.adminOnly, async (req, res, next)=>{ + try { + 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.message, ' }'); + return res.status(500).json({ message: error.message }); + } }); router.get('/admin', mw.adminOnly, (req, res)=>{ @@ -177,10 +177,10 @@ router.get('/admin', mw.adminOnly, (req, res)=>{ url : req.originalUrl }) .then((page)=>res.send(page)) - .catch((err)=> { - console.log(err) - res.sendStatus(500) - }) + .catch((err)=>{ + console.log(err); + res.sendStatus(500); + }); }); module.exports = router; diff --git a/server/notifications.model.js b/server/notifications.model.js index a834b1a65..a06eed6e7 100644 --- a/server/notifications.model.js +++ b/server/notifications.model.js @@ -3,102 +3,102 @@ const _ = require('lodash'); // Define the schema for the notification const NotificationSchema = new mongoose.Schema({ - dismissKey: { type: String, unique: true, required: true }, - title: { type: String, default: '' }, - text: { type: String, default: '' }, - createdAt: { type: Date, default: Date.now }, - startAt: { type: Date, default: Date.now }, - stopAt: { type: Date, default: Date.now }, + dismissKey : { type: String, unique: true, required: true }, + title : { type: String, default: '' }, + text : { type: String, default: '' }, + createdAt : { type: Date, default: Date.now }, + startAt : { type: Date, default: Date.now }, + stopAt : { type: Date, default: Date.now }, }, { versionKey: false }); // Static method to get a notification based on a query NotificationSchema.statics.get = async function(query, fields = null) { - try { - const notifications = await this.find(query, fields).exec(); - if (!notifications.length) throw new Error('Cannot find notification'); - return notifications[0]; - } catch (err) { - throw new Error(err.message || 'Error finding notification'); - } + try { + const notifications = await this.find(query, fields).exec(); + if(!notifications.length) throw new Error('Cannot find notification'); + return notifications[0]; + } catch (err) { + throw new Error(err.message || 'Error finding notification'); + } }; // Static method to get a notification by its dismiss key NotificationSchema.statics.getByKey = async function(key, fields = null) { - try { - const notification = await this.findOne({ dismissKey: key }, fields).lean().exec(); - if (!notification) throw new Error('Cannot find notification'); - return notification; - } catch (err) { - throw new Error(err.message || 'Error finding notification'); - } + try { + const notification = await this.findOne({ dismissKey: key }, fields).lean().exec(); + if(!notification) throw new Error('Cannot find notification'); + return notification; + } catch (err) { + throw new Error(err.message || 'Error finding notification'); + } }; // Static method to add a new notification NotificationSchema.statics.addNotification = async function(data) { - if (!data.dismissKey) return 'Dismiss key is required!'; - const defaults = { - title: '', - text: '', - startAt: new Date(), - stopAt: new Date() - }; - _.defaults(data, defaults); - const newNotification = new this(data); - try { - const savedNotification = await newNotification.save(); - return savedNotification; - } catch (err) { - throw new Error(err.message || 'Error saving notification'); - } + if(!data.dismissKey) return 'Dismiss key is required!'; + const defaults = { + title : '', + text : '', + startAt : new Date(), + stopAt : new Date() + }; + _.defaults(data, defaults); + const newNotification = new this(data); + try { + const savedNotification = await newNotification.save(); + return savedNotification; + } catch (err) { + throw new Error(err.message || 'Error saving notification'); + } }; // Static method to update a notification NotificationSchema.statics.updateNotification = async function(dismissKey, title = null, text = null, startAt = null, stopAt = null) { - if (!dismissKey) return 'No key!'; - if (!title && !text && !startAt && !stopAt) return 'No data!'; - const filter = { dismissKey: dismissKey }; - const data = { title, text, startAt, stopAt }; + if(!dismissKey) return 'No key!'; + if(!title && !text && !startAt && !stopAt) return 'No data!'; + const filter = { dismissKey: dismissKey }; + const data = { title, text, startAt, stopAt }; - // Remove null values from the data object - for (const [key, value] of Object.entries(data)) { - if (value === null) delete data[key]; - } + // Remove null values from the data object + for (const [key, value] of Object.entries(data)) { + if(value === null) delete data[key]; + } - try { - const updatedNotification = await this.findOneAndUpdate(filter, data, { new: true }).exec(); - if (!updatedNotification) throw new Error('Cannot find notification'); - return updatedNotification; - } catch (err) { - throw new Error(err.message || 'Error updating notification'); - } + try { + const updatedNotification = await this.findOneAndUpdate(filter, data, { new: true }).exec(); + if(!updatedNotification) throw new Error('Cannot find notification'); + return updatedNotification; + } catch (err) { + throw new Error(err.message || 'Error updating notification'); + } }; // Static method to delete a notification NotificationSchema.statics.deleteNotification = async function(dismissKey) { - if (!dismissKey) return 'No key provided!'; - try { - const deletedNotification = await this.findOneAndDelete({ dismissKey }).exec(); - if (!deletedNotification) throw new Error('Notification not found'); - return deletedNotification; - } catch (err) { - throw new Error(err.message || 'Error deleting notification'); - } + if(!dismissKey) return 'No key provided!'; + try { + const deletedNotification = await this.findOneAndDelete({ dismissKey }).exec(); + if(!deletedNotification) throw new Error('Notification not found'); + return deletedNotification; + } catch (err) { + throw new Error(err.message || 'Error deleting notification'); + } }; // Static method to get all notifications NotificationSchema.statics.getAll = async function() { - try { - const notifications = await this.find().exec(); - return notifications; - } catch (err) { - throw new Error(err.message || 'Error retrieving notifications'); - } + try { + const notifications = await this.find().exec(); + return notifications; + } catch (err) { + throw new Error(err.message || 'Error retrieving notifications'); + } }; // Create and export the model const Notification = mongoose.model('Notification', NotificationSchema); module.exports = { - schema: NotificationSchema, - model: Notification, + schema : NotificationSchema, + model : Notification, };