Skip to content
Snippets Groups Projects
Select Git revision
  • 061e58a48279bb0142d3f094ab7baa0c6a13321a
  • master default protected
  • gh-pages
3 results

postSerie.js

Blame
  • user avatar
    Tamás Szabó authored
    061e58a4
    History
    postSerie.js 695 B
    const requireOption = require('../common').requireOption;
    /**
     * Creates a new serie with the data provided
     *
    */
    module.exports = (objectRepository) => {
      const serieModel = requireOption(objectRepository, 'serieModel');
      return (req, res, next) => {
        const { title, image, description } = req.body;
        if (title === undefined || image === undefined || description === undefined) {
          return next();
        }
        const serie = new serieModel({
          title,
          image,
          description,
          createdAt: new Date(),
          progress: 0
        });
    
        serie.save()
          .then(serie => {
            res.tpl.id = serie.id;
            return next();
          })
          .catch(err => next(err))
      };
    };