Skip to content

Instantly share code, notes, and snippets.

@tudorilisoi
Created July 12, 2018 14:12
Show Gist options
  • Save tudorilisoi/1bf7ab91eb3ca0359543af30b41ea5b9 to your computer and use it in GitHub Desktop.
Save tudorilisoi/1bf7ab91eb3ca0359543af30b41ea5b9 to your computer and use it in GitHub Desktop.
A fix for stories within blocks
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