-
-
Save Raynos/1149020 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// create new post | |
app.post("/blog", function _create(req, res) { | |
var post = { | |
"content": req.body.content, | |
"title": req.body.title, | |
"datetime": Date.now(), | |
"type": "post" | |
} | |
model.get(function _get(err, rows) { | |
// get highest id and make the new id one higher. | |
var id = rows.map(function _pluckId(v) { | |
return v.value.id; | |
}).reduce(function _findMaxId(prev, curr) { | |
return prev < curr ? curr : prev; | |
}, 0); | |
post.id = ++id; | |
model.create(post, function _save() { | |
res.redirect("blog/" + view.url(post)); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment