Guest User

Untitled

a guest
Feb 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.17 KB | None | 0 0
  1. router.get('/locations/:locationid/reviews/:reviewid', ctrlReviews.reviewsReadOne);
  2.  
  3. module.exports.reviewsReadOne = function(req, res) {
  4. if (req.params && req.params.locationid && req.params.reviewid){
  5. Loc
  6. .findById(req.params.locationid)
  7. .select('name reviews')
  8. .exec((err, location)=>{
  9. let response, review;
  10. if(!location){
  11. sendJSONresponse(res, 404, {
  12. "message": "location not found"
  13. });
  14. return;
  15. }else if (err){
  16. sendJSONresponse(res, 400, err);
  17. return;
  18. }
  19. if(location.reviews && location.reviews.length > 0){
  20.  
  21. review = location.reviews.id(req.params.reviewid);
  22.  
  23. if(!review){
  24. sendJSONresponse(res, 404, {
  25. "message": "review id not found"
  26. })
  27. }else {
  28. response = {
  29. location : {
  30. name: location.name,
  31. id: req.params.locationid
  32. },
  33. review: review
  34. };
  35. sendJSONresponse(res, 200, response);
  36. }
  37. }else {
  38. sendJSONresponse(res, 404, {
  39. "message": "No reviews found"
  40. });
  41. }
  42.  
  43. })
  44. } else {
  45. sendJSONresponse(res, 404, {
  46. "message": "Not found location and review id are both required"
  47. })
  48. }
  49.  
  50. CoreMongooseArray [
  51. { createdOn: 2019-02-18T19:30:06.942Z,
  52. author: 'Димка',
  53. rating: 3,
  54. id: 5c66d32696e86adbe6eff4eb,
  55. timestamp: 2017-07-21T21:00:00.000Z,
  56. reviewText: 'Комментарий о заведении' },
  57. { createdOn: 2019-02-18T19:30:06.942Z,
  58. author: 'Петька',
  59. id: 5c66d32696e86adbe6eff4ec,
  60. rating: 3,
  61. timestamp: 2018-05-31T21:00:00.000Z,
  62. reviewText: 'Еще один комментарий о этом кафе' },
  63. { createdOn: 2019-02-18T19:30:06.941Z,
  64. author: 'Олька',
  65. id: 5c66d32696e86adbe6eff4ed,
  66. rating: 3,
  67. timestamp: 2018-06-10T21:00:00.000Z,
  68. reviewText: 'Снова комментарий для кофейни' },
  69. _path: 'reviews',
  70. toBSON: [Function: toBSON],
  71. _atomics: {},
  72. _parent: { _id: 5c66d32696e86adbe6eff4ee,
  73. name: 'CoffeeMax',
  74. reviews: [ [Object], [Object], [Object] ] },
  75. _cast: [Function: _cast],
  76. _markModified: [Function: _markModified],
  77. _registerAtomic: [Function: _registerAtomic],
  78. '$__getAtomics': [Function: $__getAtomics],
  79. hasAtomics: [Function: hasAtomics],
  80. _mapCast: [Function: _mapCast],
  81. push: [Function: push],
  82. nonAtomicPush: [Function: nonAtomicPush],
  83. '$pop': [Function: $pop],
  84. pop: [Function: pop],
  85. '$shift': [Function: $shift],
  86. shift: [Function: shift],
  87. pull: [Function: pull],
  88. splice: [Function: splice],
  89. unshift: [Function: unshift],
  90. sort: [Function: sort],
  91. addToSet: [Function: addToSet],
  92. set: [Function: set],
  93. toObject: [Function: toObject],
  94. inspect: [Function: inspect],
  95. indexOf: [Function: indexOf],
  96. remove: [Function: pull],
  97. id: [Function: id],
  98. create: [Function: create],
  99. notify: [Function: notify],
  100. isMongooseDocumentArray: true,
  101. validators: [],
  102. _schema: DocumentArray {
  103. casterConstructor:
  104. { [Function: EmbeddedDocument]
  105. schema: [Schema],
  106. '$isArraySubdocument': true,
  107. events: [EventEmitter],
  108. _events: undefined,
  109. _eventsCount: 0,
  110. _maxListeners: undefined,
  111. setMaxListeners: [Function: setMaxListeners],
  112. getMaxListeners: [Function: getMaxListeners],
  113. emit: [Function: emit],
  114. addListener: [Function: addListener],
  115. on: [Function: addListener],
  116. prependListener: [Function: prependListener],
  117. once: [Function: once],
  118. prependOnceListener: [Function: prependOnceListener],
  119. removeListener: [Function: removeListener],
  120. off: [Function: removeListener],
  121. removeAllListeners: [Function: removeAllListeners],
  122. listeners: [Function: listeners],
  123. rawListeners: [Function: rawListeners],
  124. listenerCount: [Function: listenerCount],
  125. eventNames: [Function: eventNames],
  126. options: [Object],
  127. path: 'reviews',
  128. base: [Mongoose],
  129. '$appliedMethods': true,
  130. '$appliedHooks': true,
  131. _middleware: [Kareem] },
  132. caster:
  133. { [Function: EmbeddedDocument]
  134. schema: [Schema],
  135. '$isArraySubdocument': true,
  136. events: [EventEmitter],
  137. _events: undefined,
  138. _eventsCount: 0,
  139. _maxListeners: undefined,
  140. setMaxListeners: [Function: setMaxListeners],
  141. getMaxListeners: [Function: getMaxListeners],
  142. emit: [Function: emit],
  143. addListener: [Function: addListener],
  144. on: [Function: addListener],
  145. prependListener: [Function: prependListener],
  146. once: [Function: once],
  147. prependOnceListener: [Function: prependOnceListener],
  148. removeListener: [Function: removeListener],
  149. off: [Function: removeListener],
  150. removeAllListeners: [Function: removeAllListeners],
  151. listeners: [Function: listeners],
  152. rawListeners: [Function: rawListeners],
  153. listenerCount: [Function: listenerCount],
  154. eventNames: [Function: eventNames],
  155. options: [Object],
  156. path: 'reviews',
  157. base: [Mongoose],
  158. '$appliedMethods': true,
  159. '$appliedHooks': true,
  160. _middleware: [Kareem] },
  161. '$isMongooseArray': true,
  162. path: 'reviews',
  163. instance: 'Array',
  164. validators: [],
  165. getters: [],
  166. setters: [],
  167. options: { type: [Array] },
  168. _index: null,
  169. defaultValue: [Function],
  170. schema:
  171. Schema {
  172. obj: [Object],
  173. paths: [Object],
  174. aliases: {},
  175. subpaths: {},
  176. virtuals: [Object],
  177. singleNestedPaths: {},
  178. nested: {},
  179. inherits: {},
  180. callQueue: [],
  181. _indexes: [],
  182. methods: {},
  183. methodOptions: {},
  184. statics: {},
  185. tree: [Object],
  186. query: {},
  187. childSchemas: [],
  188. plugins: [Array],
  189. '$id': 2,
  190. s: [Object],
  191. _userProvidedOptions: {},
  192. options: [Object],
  193. '$globalPluginsApplied': true,
  194. _requiredpaths: [] },
  195. schemaOptions: {},
  196. '$isMongooseDocumentArray': true,
  197. Constructor:
  198. { [Function: EmbeddedDocument]
  199. schema: [Schema],
  200. '$isArraySubdocument': true,
  201. events: [EventEmitter],
  202. _events: undefined,
  203. _eventsCount: 0,
  204. _maxListeners: undefined,
  205. setMaxListeners: [Function: setMaxListeners],
  206. getMaxListeners: [Function: getMaxListeners],
  207. emit: [Function: emit],
  208. addListener: [Function: addListener],
  209. on: [Function: addListener],
  210. prependListener: [Function: prependListener],
  211. once: [Function: once],
  212. prependOnceListener: [Function: prependOnceListener],
  213. removeListener: [Function: removeListener],
  214. off: [Function: removeListener],
  215. removeAllListeners: [Function: removeAllListeners],
  216. listeners: [Function: listeners],
  217. rawListeners: [Function: rawListeners],
  218. listenerCount: [Function: listenerCount],
  219. eventNames: [Function: eventNames],
  220. options: [Object],
  221. path: 'reviews',
  222. base: [Mongoose],
  223. '$appliedMethods': true,
  224. '$appliedHooks': true,
  225. _middleware: [Kareem] } },
  226. _handlers: { isNew: [Function: notify], save: [Function: notify] } ]
Add Comment
Please, Sign In to add comment