Guest User

Untitled

a guest
Dec 16th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. const blogArticleServices = require('../services/blog-articles.service')
  2.  
  3. module.exports = {
  4. checkCurrentPublishingDate,
  5. requireFuturePublishingDate
  6. }
  7.  
  8. function checkCurrentPublishingDate(req, res, next) {
  9. const model = req.model
  10. const date = new Date()
  11. blogArticleServices.readById(model._id).then(data => {
  12. if (data.datePublished < date && Date.parse(data.datePublished) !== Date.parse(model.datePublished)) {
  13. res.status(400).send({
  14. name: 'PublicationError',
  15. details: [
  16. {
  17. message: 'You are attempting to submit a publishing date for and article that is already published'
  18. }
  19.  
  20. ]
  21. })
  22. return
  23. } else if (data.datePublished > date && model.datePublished < date) {
  24. res.status(400).send({
  25. name: 'PublicationError',
  26. details: [
  27. {
  28. message: 'You are attempting to submit a publication date in the past'
  29. }
  30.  
  31. ]
  32. })
  33. return
  34. }
  35. next()
  36. })
  37. }
  38.  
  39. function requireFuturePublishingDate(req, res, next) {
  40. let date = new Date()
  41. if (req.model.datePublished < date) {
  42. res.status(400).send({
  43. name: 'PublicationError',
  44. details: [
  45. {
  46. message: 'You are attempting to submit a publishing date that is in the past'
  47. }
  48. ]
  49. })
  50. return
  51. }
  52. next()
  53. }
Add Comment
Please, Sign In to add comment