post.js 822 B

123456789101112131415161718192021222324252627282930
  1. var express = require('express');
  2. var router = express.Router();
  3. const posts = new require('../db/Posts');
  4. /* post view */
  5. router.get('/:id?/:action', function(req, res, next) {
  6. let partial = req.params.action.toLowerCase()
  7. if (Number(req.params.id)) {
  8. console.log(`Request action: ${partial} over post: ${req.params.id}`)
  9. posts.fetchByPK(['id', 'title', 'markdown', 'html', 'tags', 'status'], req.params.id, function (err, row) {
  10. if (err) {
  11. res.render('partial/error.njk', { error: err })
  12. } else {
  13. res.render(`partial/${partial}.njk`, { selected: row });
  14. }
  15. }
  16. )
  17. } else {
  18. res.render('partial/edit.njk');
  19. }
  20. });
  21. router.put('/', function(req, res, next) {
  22. let post = req.body
  23. post.html = 'HTML'
  24. posts.update(post)
  25. })
  26. module.exports = router