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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user