Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var mongoose = require('mongoose');
  4. var DashboardEntry = mongoose.model('DashboardEntry');
  5. var Contactable = mongoose.model('Contactable');
  6.  
  7. module.exports = function(app) {
  8. /** Return the user's dashboard entry. */
  9. app.get('/api/dashboard/getUserDashboard', function(req, res) {
  10. var data = req.body;
  11. var userId = data.userId;
  12. DashboardEntry.find({"user": userId}, function(err, doc) {
  13. if (err) {
  14. console.log("error getting dashboard for user " + userId);
  15. res.send(err);
  16. } else {
  17. res.jsonp(doc);
  18. }
  19. });
  20. });
  21.  
  22. /** Updates the user's location. */
  23. app.post('/api/dashboard/location/update', function(req, res) {
  24. var data = req.body;
  25. var userId = data.userId;
  26. var location = data.location;
  27. var query = {'user', userId};
  28. DashboardEntry.update(query, {$set:{'location': location}}, function(err, doc) {
  29. if (err) {
  30. console.log("error updating location for user " + userId);
  31. res.send(err);
  32. } else {
  33. res.jsonp(doc);
  34. }
  35. });
  36. });
  37.  
  38. /** Updates the user's bio on the dashboard. */
  39. app.post('/api/dashboard/bio/update', function(req, res) {
  40. var data = req.body;
  41. var userId = data.userId;
  42. var bio = data.bio;
  43. var query = {'user': userId};
  44. DashboardEntry.update(query, {$set:{'bio': bio}}, function(err, doc) {
  45. if (err) {
  46. console.log("error updating bio for user " + userId);
  47. res.send(err);
  48. } else {
  49. res.jsonp(doc);
  50. }
  51. });
  52. });
  53.  
  54. /** Update the user's contacts list with a new contact. */
  55. app.post('/api/dashboard/contacts/addContact', function(req, res) {
  56. // TODO: Grab the contact's info from the users collection.
  57. var data = req.body;
  58. var userId = data.userId;
  59. var contactsId = data.contactId;
  60. var query = {'user', userId};
  61. Contactable.update(query, {$push:{'contacts'}}, function(err, doc) {
  62. if (err) {
  63. console.log('error adding contact ' + contactInfo + 'to user ' +
  64. userId + ' contacts'});
  65. console.log(err);
  66. res.send(err);
  67. } else {
  68. res.jsonp(doc);
  69. }
  70. });
  71.  
  72. });
  73.  
  74. /** Update the user's profile pic to a new url. */
  75. app.post('/api/dashboard/profilePic/update', function(req, res) {
  76. //TODO
  77. });
  78. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement