mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 16:22:44 +00:00
adress comments
This commit is contained in:
@@ -75,7 +75,7 @@ describe('Tests for admin api', ()=>{
|
||||
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body).toEqual({ success: true, message: 'Notification deleted successfully' });
|
||||
expect(response.body).toEqual({ message: 'Notification deleted successfully' });
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ const NotificationSchema = new mongoose.Schema({
|
||||
}, { versionKey: false });
|
||||
|
||||
NotificationSchema.statics.addNotification = async function(data) {
|
||||
if(!data.dismissKey) return { success: false, message: 'Dismiss key is required!' };
|
||||
if(!data.dismissKey) return { message: 'Dismiss key is required!' };
|
||||
|
||||
const defaults = {
|
||||
title : '',
|
||||
@@ -22,39 +22,35 @@ NotificationSchema.statics.addNotification = async function(data) {
|
||||
|
||||
const notificationData = _.defaults(data, defaults);
|
||||
|
||||
if(!(notificationData.startAt instanceof Date) || !(notificationData.stopAt instanceof Date)) {
|
||||
return { success: false, message: 'Invalid date format for startAt or stopAt' };
|
||||
}
|
||||
|
||||
try {
|
||||
const newNotification = new this(notificationData);
|
||||
const savedNotification = await newNotification.save();
|
||||
return { success: true, notification: savedNotification };
|
||||
return { notification: savedNotification };
|
||||
} catch (err) {
|
||||
return { success: false, message: err.message || 'Error saving notification' };
|
||||
return { message: err.message || 'Error saving notification' };
|
||||
}
|
||||
};
|
||||
|
||||
NotificationSchema.statics.deleteNotification = async function(dismissKey) {
|
||||
if(!dismissKey) return { success: false, message: 'No key provided!' };
|
||||
if(!dismissKey) return { message: 'No key provided!' };
|
||||
|
||||
try {
|
||||
const deletedNotification = await this.findOneAndDelete({ dismissKey }).exec();
|
||||
if(!deletedNotification) {
|
||||
return { success: false, message: 'Notification not found' };
|
||||
return { message: 'Notification not found' };
|
||||
}
|
||||
return { success: true, message: 'Notification deleted successfully' }; // Update response here
|
||||
return { message: 'Notification deleted successfully' }; // Update response here
|
||||
} catch (err) {
|
||||
return { success: false, message: err.message || 'Error deleting notification' };
|
||||
return { message: err.message || 'Error deleting notification' };
|
||||
}
|
||||
};
|
||||
|
||||
NotificationSchema.statics.getAll = async function() {
|
||||
try {
|
||||
const notifications = await this.find().exec();
|
||||
return { success: true, notifications };
|
||||
return { notifications };
|
||||
} catch (err) {
|
||||
return { success: false, message: err.message || 'Error retrieving notifications' };
|
||||
return { message: err.message || 'Error retrieving notifications' };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user