Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. var getSlug = require('speakingurl').createSlug({ lang: 'pt' });
  2.  
  3. module.exports = (app) => {
  4.  
  5. app.post('/new', (req, res) => {
  6. var mongo = new app.database.Mongo();
  7.  
  8. mongo.findOne({ username: req.body.author }, 'users')
  9. .then(author => {
  10.  
  11. var post = {
  12. title: req.body.title,
  13. content: req.body.content,
  14. author: author,
  15. tags: req.body.tags,
  16. url: getSlug(req.body.title),
  17. date: new Date(),
  18. draft: true,
  19. };
  20.  
  21. mongo.insert(post, 'posts')
  22. .then(() => {
  23. res.status(200).json({ status: 'ok' });
  24. }).catch(err => {
  25. res.status(500).json({ error: err })
  26. });
  27. }).catch(err => {
  28. res.status(500).json({ error: err })
  29. });
  30. });
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement