Guest User

Untitled

a guest
May 8th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. // post route for getting the review
  2. router.post('/:id', isLoggedIn, function(req, res) {
  3.  
  4. Work.findById(req.params.id, function(err, foundWork) {
  5. if (err) {
  6. console.log(err);
  7. } else {
  8.  
  9. // create a new critique
  10. var newCritique = new Critique ({
  11. reviewerName: {
  12. id: req.user._id,
  13. username: req.user.username
  14. },
  15. work: {
  16. id: foundWork._id,
  17. title: foundWork.title
  18. },
  19. critique : req.body.critique,
  20. date: Date.now(),
  21. rating: 0
  22. });
  23.  
  24. // save new critique to db
  25. Critique.create(newCritique, function(err, createdCritique) {
  26. if (err) {
  27. console.log(err)
  28. } else {
  29. console.log("Created critique is ");
  30. console.log(createdCritique);
  31.  
  32. // push the new critique into array of critiques of the work
  33. foundWork.critiques.push(createdCritique);
  34. // save to db
  35. foundWork.save();
  36. }
  37. });
  38. }
  39. });
  40.  
  41. var mongoose = require('mongoose');
  42. var passportLocalMongoose = require('passport-local-mongoose');
  43.  
  44. var UserSchema = new mongoose.Schema({
  45. firstname: String,
  46. lastname: String,
  47. username: String,
  48. password: String,
  49. email: String,
  50. zip: String,
  51. bio: {
  52. type: String,
  53. default: ''
  54. },
  55. influences: {
  56. type: String,
  57. default: ''
  58. },
  59. favBooks: {
  60. type: String,
  61. default: ''
  62. },
  63. notWriting: {
  64. type: String,
  65. default: ''
  66. },
  67. favHero: {
  68. type: String,
  69. default: ''
  70. },
  71. favVillain: {
  72. type: String,
  73. default: ''
  74. },
  75. works: [
  76. {
  77. type: mongoose.Schema.Types.ObjectId,
  78. ref: 'Work'
  79. }
  80. ],
  81. critiques: [
  82. {
  83. type: mongoose.Schema.Types.ObjectId,
  84. ref: 'Critique'
  85. }
  86. ],
  87. friends: [
  88. {
  89. friendId: String,
  90. friendName : String,
  91. friendPic: String
  92. }
  93. ],
  94. friendRequests: [
  95. {
  96. sendingFriendId: String,
  97. sendingFriendName : String,
  98. sendingFriendPic: String
  99. }
  100. ],
  101. createdDate: {
  102. type: Date,
  103. default: Date.now
  104. },
  105. lastLogin: {
  106. type: Date,
  107. default: Date.now
  108. }
  109. });
  110.  
  111. UserSchema.plugin(passportLocalMongoose);
  112. module.exports = mongoose.model("User", UserSchema);
  113.  
  114. var mongoose = require('mongoose');
  115.  
  116. var WorkSchema = new mongoose.Schema({
  117. title: String,
  118. genre: String,
  119. workType: String,
  120. length: Number,
  121. ageRange: String,
  122. author: {
  123. id: {
  124. type: mongoose.Schema.Types.ObjectId,
  125. ref: "User"
  126. },
  127. username: String
  128. },
  129. manuscriptText: String,
  130. critiques: [
  131. {
  132. id: {
  133. type: mongoose.Schema.Types.ObjectId,
  134. ref: "Critique"
  135. }
  136. }
  137. ],
  138. ratingNumber: [Number],
  139. ratingSum: {
  140. type: Number,
  141. default: 0
  142. },
  143. date: {
  144. type: Date,
  145. default: Date.now
  146. },
  147. isPublic: {
  148. type: Boolean,
  149. default: true
  150. }
  151. });
  152.  
  153.  
  154. module.exports = mongoose.model("Work", WorkSchema);
  155.  
  156. var mongoose = require('mongoose');
  157. var passportLocalMongoose = require('passport-local-mongoose');
  158.  
  159. var CritiqueSchema = new mongoose.Schema({
  160. reviewerName: {
  161. id: {
  162. type: mongoose.Schema.Types.ObjectId,
  163. ref: "User"
  164. },
  165. username: String
  166. },
  167. work: {
  168. id: {
  169. type: mongoose.Schema.Types.ObjectId,
  170. ref: "Work"
  171. },
  172. title: String
  173. },
  174. critique: String,
  175. date: {
  176. type: Date,
  177. default: Date.now
  178. },
  179. rating: [Number]
  180. });
  181.  
  182.  
  183. CritiqueSchema.plugin(passportLocalMongoose);
  184. module.exports = mongoose.model("Critique", CritiqueSchema);
Add Comment
Please, Sign In to add comment