watch.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var Watch = require('../models/Watch');
  2. var mongoose = require('mongoose');
  3. const bodyParser = require('body-parser');
  4. // Get Movie or Series
  5. exports.watchGet = function(req, res){
  6. Watch.findOne({ 'permalink': req.params.permalink }, function(err, w){
  7. if (!w) {
  8. return res.redirect('/404');
  9. }
  10. else{
  11. res.render('watch', {
  12. title: w.title,
  13. layout: w.layout,
  14. subtitle: w.subtitle,
  15. sinopse: w.sinopse,
  16. year: w.year,
  17. imgbg: w.imgbg,
  18. video: w.video,
  19. thumb480: w.thumb480,
  20. thumb130: w.thumb130,
  21. runtime: w.runtime,
  22. eps: w.eps
  23. });
  24. }
  25. });
  26. };
  27. // GET New Production
  28. exports.newWatchGet = function(req, res) {
  29. if (!req.user) {
  30. return res.redirect('/login');
  31. }
  32. res.render('novo', {
  33. title: 'Criar Nova Produção'
  34. });
  35. };
  36. // POST New Production
  37. exports.newWatchPost = function(req, res, next) {
  38. var body = req.body;
  39. // para retornar depois do erro
  40. var form = {
  41. };
  42. var errors = req.validationErrors();
  43. if (errors) {
  44. req.flash('error', errors);
  45. return res.render('novo', {form: form});
  46. }
  47. Watch.findOne({ permalink: req.body.permalink }, function(err, watch) {
  48. if (watch) {
  49. req.flash('error', { msg: 'O permalink inserido já existe. Tente outro.' });
  50. return res.redirect('/novo');
  51. }
  52. // Para salvar no BD
  53. watch = new Watch({
  54. criador: req.user.id,
  55. permalink: req.body.permalink,
  56. layout: 'filme',
  57. featured : false,
  58. title: req.body.title,
  59. subtitle: req.body.subtitle,
  60. sinopse: req.body.sinopse,
  61. year: req.body.year,
  62. classind: req.body.classind,
  63. duration: req.body.duration,
  64. video: req.body.video,
  65. thumb480: req.body.thumb480,
  66. imgbg: req.body.imgbg,
  67. tags: req.body.tags
  68. });
  69. watch.save(function(err) {
  70. //req.logIn(campanha, function(err) {
  71. req.flash('success', { msg: 'Muito obrigado por sua colaboração. Em breve a produção estará no ar. <3' });
  72. res.redirect('/');
  73. //});
  74. });
  75. });
  76. };
  77. // GET Tags
  78. exports.tagsGet = function(req, res){
  79. Watch.find({ 'tags': req.params.tags }, null, {sort: '-year'}, function(err, w){
  80. if (!w) {
  81. return res.redirect('/404');
  82. }
  83. else{
  84. res.render('home', {
  85. title: 'Tag',
  86. tag: req.params.tags,
  87. watch: w
  88. });
  89. }
  90. });
  91. };
  92. //Get Edit Watch
  93. exports.watchEdit = function(req, res){
  94. Watch.findOne({ '_id': req.params._id }, function(err, w){
  95. if (!w) {
  96. return res.redirect('/404');
  97. }
  98. else{
  99. res.render('edit', {
  100. w: w
  101. });
  102. }
  103. });
  104. };
  105. // PUT or Update a Production
  106. exports.watchPut = function(req, res, next) {
  107. var body = req.body;
  108. Watch.findById(req.params._id, function(err, watch) {
  109. // Para salvar no BD
  110. watch.criador = req.user.id;
  111. watch.permalink = req.body.permalink;
  112. watch.layout = req.body.layout;
  113. watch.license = req.body.license;
  114. watch.featured = req.body.featured;
  115. watch.title = req.body.title;
  116. watch.subtitle = req.body.subtitle;
  117. watch.sinopse = req.body.sinopse;
  118. watch.year = req.body.year;
  119. watch.classind = req.body.classind;
  120. watch.duration = req.body.duration;
  121. watch.video = req.body.video;
  122. watch.thumb480 = req.body.thumb480;
  123. watch.imgbg = req.body.imgbg;
  124. watch.tags = req.body.tags;
  125. watch.top = req.body.top
  126. watch.save(function(err) {
  127. req.flash('success', { msg: 'Alterações feitas com sucesso.' });
  128. res.redirect('/edit/' + req.params._id);
  129. });
  130. });
  131. };