Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const blogArticleServices = require('../services/blog-articles.service')
- module.exports = {
- checkCurrentPublishingDate,
- requireFuturePublishingDate
- }
- function checkCurrentPublishingDate(req, res, next) {
- const model = req.model
- const date = new Date()
- blogArticleServices.readById(model._id).then(data => {
- if (data.datePublished < date && Date.parse(data.datePublished) !== Date.parse(model.datePublished)) {
- res.status(400).send({
- name: 'PublicationError',
- details: [
- {
- message: 'You are attempting to submit a publishing date for and article that is already published'
- }
- ]
- })
- return
- } else if (data.datePublished > date && model.datePublished < date) {
- res.status(400).send({
- name: 'PublicationError',
- details: [
- {
- message: 'You are attempting to submit a publication date in the past'
- }
- ]
- })
- return
- }
- next()
- })
- }
- function requireFuturePublishingDate(req, res, next) {
- let date = new Date()
- if (req.model.datePublished < date) {
- res.status(400).send({
- name: 'PublicationError',
- details: [
- {
- message: 'You are attempting to submit a publishing date that is in the past'
- }
- ]
- })
- return
- }
- next()
- }
Add Comment
Please, Sign In to add comment