Advertisement
mustyumr

controller

Sep 20th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. 'use strict';
  2.  
  3. /**
  4. * Module dependencies.
  5. */
  6. var mongoose = require('mongoose');
  7. var Calllog = mongoose.model('Calllog');
  8.  
  9. _ = require('lodash');
  10.  
  11.  
  12. /**
  13. * Find user by id
  14. */
  15. /*exports.all = function(req, res) {
  16. res.jsonp({user:'cccc'});
  17. };*/
  18.  
  19. module.exports = function(Calllogs) {
  20. console.log('this is working');
  21.  
  22. return {
  23. /**
  24.  
  25.  
  26.  
  27. * Find calllog by id
  28. */
  29. callLog: function(req, res, next, id) {
  30.  
  31. Calllog.load(id, function(err, calllog) {
  32. if (err) return next(err);
  33. if (!calllog) return next(new Error('Failed to load calllog ' + id));
  34. req.calllog = calllog;
  35. next();
  36. });
  37. },
  38. /**
  39. * Create an calllog
  40. */
  41. create: function(req, res) {
  42.  
  43. console.log(req.body);
  44.  
  45. // var calllog = new Calllog ();
  46. // console.log("call log", Calllog);
  47. // console.log("req body", req.body);
  48.  
  49.  
  50.  
  51. // //var calllog = new Calllog(calllog);
  52.  
  53. // calllog.save(function (err, docs) {
  54. // if (err){
  55. // console.log('Error');
  56. // }
  57. // else{
  58. // Calllog.count(req.body.displayName, function(err, c)
  59.  
  60. // {
  61. // console.log('Count is ' + c);
  62. // console.log(docs);
  63. // console.log(req.body.displayName);
  64. // })
  65.  
  66. // }
  67.  
  68. // })
  69.  
  70. },
  71.  
  72.  
  73.  
  74. // create: function(req, res) {
  75. // console.log("i created");
  76. // // Calllog.displayName = req.body.displayName;
  77.  
  78.  
  79. // var calllog = new Calllog();
  80. // // calllog.user = req.user;
  81. // calllog.dn = req.body.displayName
  82. // calllog.pn = req.body.phoneNumber
  83.  
  84. // calllog.save(function(err) {
  85.  
  86. // if (err) {
  87. // // return res.status(500).json({
  88. // // error: 'Cannot save the calllog'
  89. // // });
  90. // console.log("i did not save")
  91. // }
  92.  
  93.  
  94. // console.log("req-->", req.body)
  95. // console.log("d "+ calllog.dn)
  96. // console.log(Calllog)
  97. // res.json(calllog)
  98. // });
  99. // },
  100. /**
  101. * Update an calllog
  102. */
  103. update: function(req, res) {
  104. var calllog = req.calllog;
  105.  
  106. calllog = _.extend(calllog, req.body);
  107.  
  108.  
  109. calllog.save(function(err) {
  110. if (err) {
  111. return res.status(500).json({
  112. error: 'Cannot update the calllog'
  113. });
  114. }
  115.  
  116. res.json(calllog);
  117. });
  118. },
  119. /**
  120. * Delete a calllog
  121. */
  122. destroy: function(req, res) {
  123. var calllog = req.calllog;
  124.  
  125.  
  126. calllog.remove(function(err) {
  127. if (err) {
  128. return res.status(500).json({
  129. error: 'Cannot delete the calllog'
  130. });
  131. }
  132.  
  133.  
  134.  
  135. res.json(calllog);
  136. });
  137. },
  138.  
  139. /**
  140. * List of Articles
  141. */
  142. all: function(req, res) {
  143.  
  144. console.log("call all...")
  145.  
  146. Calllog.find({}).sort('-created').populate('user', 'name username').limit(20).exec(function(err, calllog) {
  147. if (err) {
  148.  
  149. return res.status(500).json({
  150. error: 'Cannot list the calllogs'
  151. });
  152. }else{
  153. console.log('i am viewed')
  154.  
  155. }
  156.  
  157. res.json(calllog)
  158. });
  159.  
  160. }
  161. };
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement