profile.js 737 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var User = require('../models/User');
  3. var Watch = require('../models/Watch');
  4. var mongoose = require('mongoose');
  5. const bodyParser = require('body-parser');
  6. /**
  7. * Get the profile of someone
  8. */
  9. exports.profileGet = function(req, res){
  10. var options = {
  11. profile: [],
  12. watch: []
  13. }
  14. User.findOne({ 'username': req.params.username }, function(err, p){
  15. if(!p){
  16. return res.redirect('/404');
  17. }
  18. if (p) {
  19. options.p = p
  20. Watch.find({'criador': options.p._id}, null, {sort: '-id'}, function(err, watch){
  21. if (watch) {
  22. options.watch = watch
  23. }
  24. else {
  25. options.watch = null
  26. }
  27. res.render('profile', options);
  28. }).limit();
  29. }
  30. });
  31. };