Guest User

Untitled

a guest
Oct 8th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. TypeError: Cannot read property '_id' of undefined (en el controlador del task que esta adjuntado abajo)
  2.  
  3. let taskSchema = new Schema({
  4.  
  5. description: {
  6.  
  7. type: String,
  8. required: [true, 'The description of the task is obligatory'],
  9. unique: true
  10.  
  11. },
  12.  
  13. completed: {
  14.  
  15. type: Boolean,
  16. required: false,
  17. default: false
  18.  
  19. },
  20.  
  21. user: {
  22.  
  23. type: Schema.Types.ObjectId,
  24. ref: 'User'
  25.  
  26. }
  27.  
  28. });`
  29.  
  30. let userSchema = new Schema({
  31.  
  32. name: {
  33.  
  34. type: String,
  35. required: [true, "The name is obligatory"]
  36.  
  37. },
  38.  
  39. email: {
  40.  
  41. type: String,
  42. required: [true, "The email is obligatory"],
  43. unique: true
  44.  
  45. },
  46.  
  47. password: {
  48.  
  49. type: String,
  50. required: [true, "The password is obligatory"]
  51.  
  52. },
  53.  
  54. identification: {
  55.  
  56. type: String,
  57. required: [true, "The identification is obligatory"],
  58. unique: true
  59.  
  60. },
  61.  
  62. role: {
  63.  
  64. type: String,
  65. enum: validRoles,
  66. required: false,
  67. default: "USER"
  68.  
  69. },
  70.  
  71. online: {
  72.  
  73. type: Boolean,
  74. default: false
  75.  
  76. },
  77.  
  78. birthday: {
  79.  
  80. type: Date,
  81. required: false,
  82.  
  83. },
  84.  
  85. tasks: {
  86.  
  87. type: Array,
  88. required: false,
  89. default: []
  90.  
  91. }
  92.  
  93. });
  94.  
  95. let body = req.body;
  96.  
  97. let task = new Task({
  98.  
  99. (ACA ESTA EL ERROR!)user: req.user._id,
  100. description: body.description,
  101. completed: body.completed
  102.  
  103. });
  104.  
  105. task.save((err, task) => {
  106.  
  107. if (err) {
  108.  
  109. return res.status(500).json({
  110.  
  111. ok: false,
  112. err
  113.  
  114. });
  115.  
  116. }
  117.  
  118. res.json({
  119.  
  120. ok: true,
  121. task,
  122. userUpdated
  123.  
  124. });
  125.  
  126. });
Add Comment
Please, Sign In to add comment