1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-18 04:21:28 +00:00

Fixed a bug with saving while not logged in

This commit is contained in:
Scott Tolksdorf
2016-11-27 18:55:50 -05:00
parent 30942785d1
commit a634b76117
9 changed files with 37 additions and 32 deletions

View File

@@ -37,9 +37,13 @@ const getGoodBrewTitle = (text) => {
router.post('/api', (req, res)=>{
let authors = [];
if(req.account) authors = [req.account.username];
const newHomebrew = new HomebrewModel(_.merge({},
req.body,
{authors : [req.account.username]}
{authors : authors}
));
if(!newHomebrew.title){
newHomebrew.title = getGoodBrewTitle(newHomebrew.text);
@@ -58,7 +62,7 @@ router.put('/api/update/:id', (req, res)=>{
.then((brew)=>{
brew = _.merge(brew, req.body);
brew.updatedAt = new Date();
brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
if(req.account) brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
brew.save((err, obj)=>{
if(err) throw err;
return res.status(200).send(obj);