0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 07:32:40 +00:00

WIP commit

This commit is contained in:
G.Ambatte
2023-01-23 15:18:50 +13:00
parent a4e6b2358a
commit da0372e44c
3 changed files with 11 additions and 5 deletions

View File

@@ -38,8 +38,8 @@ const NotificationAdd = createClass({
dismissKey : this.state.dismissKey, dismissKey : this.state.dismissKey,
title : this.state.title, title : this.state.title,
text : this.state.text, text : this.state.text,
startAt : this.state.startAt, startAt : Date.parse(this.state.startAt),
stopAt : this.state.stopAt stopAt : Date.parse(this.state.stopAt)
}; };
const notification = await request.post('/admin/notification/add') const notification = await request.post('/admin/notification/add')
@@ -52,7 +52,10 @@ const NotificationAdd = createClass({
notificationResult : `Created notification: ${JSON.stringify(notification, null, 2)}` notificationResult : `Created notification: ${JSON.stringify(notification, null, 2)}`
}; };
if(notification.err) { if(notification.err) {
update.notificationResult = err; update.notificationResult = JSON.stringify(notification.err);
if(notification.err.code == 11000) {
update.notificationResult = `Duplicate dismissKey error! ${this.state.dismissKey} already exists.`;
}
}; };
if(!notification.err) { if(!notification.err) {
update.dismissKey = ''; update.dismissKey = '';
@@ -62,6 +65,8 @@ const NotificationAdd = createClass({
update.stopAt = ''; update.stopAt = '';
} }
console.log(update);
this.setState(update); this.setState(update);
}, },
@@ -74,7 +79,7 @@ const NotificationAdd = createClass({
<input className='fieldInput' type='text' value={this.state[field]} onChange={(e)=>this.handleChange(e, field)} placeholder={field} /> <input className='fieldInput' type='text' value={this.state[field]} onChange={(e)=>this.handleChange(e, field)} placeholder={field} />
</div>; </div>;
})} })}
{this.state.notificationResult} <div className='notificationResult'>{this.state.notificationResult}</div>
{/* <label>Dismiss Key:</label> {/* <label>Dismiss Key:</label>
<input type='text' value={this.state.dismissKey} onChange={this.handleChange} placeholder='notification key' /> <input type='text' value={this.state.dismissKey} onChange={this.handleChange} placeholder='notification key' />
<label>Title:</label> <label>Title:</label>

View File

@@ -110,6 +110,7 @@ router.get('/admin/notification/lookup/:id', mw.adminOnly, (req, res, next)=>{
/* Add new notification */ /* Add new notification */
router.post('/admin/notification/add', mw.adminOnly, async (req, res, next)=>{ router.post('/admin/notification/add', mw.adminOnly, async (req, res, next)=>{
console.log(req.body);
const notification = await NotificationModel.addNotification(req.body); const notification = await NotificationModel.addNotification(req.body);
return res.json(notification); return res.json(notification);
}); });

View File

@@ -43,7 +43,7 @@ NotificationSchema.statics.addNotification = async function(data){
const newNotification = new Notification(data); const newNotification = new Notification(data);
const savedNotification = await newNotification.save() const savedNotification = await newNotification.save()
.catch((err)=>{ .catch((err)=>{
return { err: err }; return { err };
}); });
return savedNotification; return savedNotification;