Created
July 12, 2018 14:12
-
-
Save tudorilisoi/1bf7ab91eb3ca0359543af30b41ea5b9 to your computer and use it in GitHub Desktop.
A fix for stories within blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function createStoryInBlock(req, res) { | |
const blockRecord = await BlockModel.findOne({_id: req.params.id}) | |
//this validates block _id | |
if(blockRecord === null){ | |
throw new Error('naughty naughty!') | |
} | |
const record = await StoriesModel.create({ | |
block:[blockRecord._id], | |
date: new Date(), | |
title: req.body.title || 'Untitled Story', | |
image: req.body.image, | |
content: req.body.content, | |
public: req.body.public | |
}) | |
res.json({ | |
story: record.serialize() | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment