Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.get('/locations/:locationid/reviews/:reviewid', ctrlReviews.reviewsReadOne);
- module.exports.reviewsReadOne = function(req, res) {
- if (req.params && req.params.locationid && req.params.reviewid){
- Loc
- .findById(req.params.locationid)
- .select('name reviews')
- .exec((err, location)=>{
- let response, review;
- if(!location){
- sendJSONresponse(res, 404, {
- "message": "location not found"
- });
- return;
- }else if (err){
- sendJSONresponse(res, 400, err);
- return;
- }
- if(location.reviews && location.reviews.length > 0){
- review = location.reviews.id(req.params.reviewid);
- if(!review){
- sendJSONresponse(res, 404, {
- "message": "review id not found"
- })
- }else {
- response = {
- location : {
- name: location.name,
- id: req.params.locationid
- },
- review: review
- };
- sendJSONresponse(res, 200, response);
- }
- }else {
- sendJSONresponse(res, 404, {
- "message": "No reviews found"
- });
- }
- })
- } else {
- sendJSONresponse(res, 404, {
- "message": "Not found location and review id are both required"
- })
- }
- CoreMongooseArray [
- { createdOn: 2019-02-18T19:30:06.942Z,
- author: 'Димка',
- rating: 3,
- id: 5c66d32696e86adbe6eff4eb,
- timestamp: 2017-07-21T21:00:00.000Z,
- reviewText: 'Комментарий о заведении' },
- { createdOn: 2019-02-18T19:30:06.942Z,
- author: 'Петька',
- id: 5c66d32696e86adbe6eff4ec,
- rating: 3,
- timestamp: 2018-05-31T21:00:00.000Z,
- reviewText: 'Еще один комментарий о этом кафе' },
- { createdOn: 2019-02-18T19:30:06.941Z,
- author: 'Олька',
- id: 5c66d32696e86adbe6eff4ed,
- rating: 3,
- timestamp: 2018-06-10T21:00:00.000Z,
- reviewText: 'Снова комментарий для кофейни' },
- _path: 'reviews',
- toBSON: [Function: toBSON],
- _atomics: {},
- _parent: { _id: 5c66d32696e86adbe6eff4ee,
- name: 'CoffeeMax',
- reviews: [ [Object], [Object], [Object] ] },
- _cast: [Function: _cast],
- _markModified: [Function: _markModified],
- _registerAtomic: [Function: _registerAtomic],
- '$__getAtomics': [Function: $__getAtomics],
- hasAtomics: [Function: hasAtomics],
- _mapCast: [Function: _mapCast],
- push: [Function: push],
- nonAtomicPush: [Function: nonAtomicPush],
- '$pop': [Function: $pop],
- pop: [Function: pop],
- '$shift': [Function: $shift],
- shift: [Function: shift],
- pull: [Function: pull],
- splice: [Function: splice],
- unshift: [Function: unshift],
- sort: [Function: sort],
- addToSet: [Function: addToSet],
- set: [Function: set],
- toObject: [Function: toObject],
- inspect: [Function: inspect],
- indexOf: [Function: indexOf],
- remove: [Function: pull],
- id: [Function: id],
- create: [Function: create],
- notify: [Function: notify],
- isMongooseDocumentArray: true,
- validators: [],
- _schema: DocumentArray {
- casterConstructor:
- { [Function: EmbeddedDocument]
- schema: [Schema],
- '$isArraySubdocument': true,
- events: [EventEmitter],
- _events: undefined,
- _eventsCount: 0,
- _maxListeners: undefined,
- setMaxListeners: [Function: setMaxListeners],
- getMaxListeners: [Function: getMaxListeners],
- emit: [Function: emit],
- addListener: [Function: addListener],
- on: [Function: addListener],
- prependListener: [Function: prependListener],
- once: [Function: once],
- prependOnceListener: [Function: prependOnceListener],
- removeListener: [Function: removeListener],
- off: [Function: removeListener],
- removeAllListeners: [Function: removeAllListeners],
- listeners: [Function: listeners],
- rawListeners: [Function: rawListeners],
- listenerCount: [Function: listenerCount],
- eventNames: [Function: eventNames],
- options: [Object],
- path: 'reviews',
- base: [Mongoose],
- '$appliedMethods': true,
- '$appliedHooks': true,
- _middleware: [Kareem] },
- caster:
- { [Function: EmbeddedDocument]
- schema: [Schema],
- '$isArraySubdocument': true,
- events: [EventEmitter],
- _events: undefined,
- _eventsCount: 0,
- _maxListeners: undefined,
- setMaxListeners: [Function: setMaxListeners],
- getMaxListeners: [Function: getMaxListeners],
- emit: [Function: emit],
- addListener: [Function: addListener],
- on: [Function: addListener],
- prependListener: [Function: prependListener],
- once: [Function: once],
- prependOnceListener: [Function: prependOnceListener],
- removeListener: [Function: removeListener],
- off: [Function: removeListener],
- removeAllListeners: [Function: removeAllListeners],
- listeners: [Function: listeners],
- rawListeners: [Function: rawListeners],
- listenerCount: [Function: listenerCount],
- eventNames: [Function: eventNames],
- options: [Object],
- path: 'reviews',
- base: [Mongoose],
- '$appliedMethods': true,
- '$appliedHooks': true,
- _middleware: [Kareem] },
- '$isMongooseArray': true,
- path: 'reviews',
- instance: 'Array',
- validators: [],
- getters: [],
- setters: [],
- options: { type: [Array] },
- _index: null,
- defaultValue: [Function],
- schema:
- Schema {
- obj: [Object],
- paths: [Object],
- aliases: {},
- subpaths: {},
- virtuals: [Object],
- singleNestedPaths: {},
- nested: {},
- inherits: {},
- callQueue: [],
- _indexes: [],
- methods: {},
- methodOptions: {},
- statics: {},
- tree: [Object],
- query: {},
- childSchemas: [],
- plugins: [Array],
- '$id': 2,
- s: [Object],
- _userProvidedOptions: {},
- options: [Object],
- '$globalPluginsApplied': true,
- _requiredpaths: [] },
- schemaOptions: {},
- '$isMongooseDocumentArray': true,
- Constructor:
- { [Function: EmbeddedDocument]
- schema: [Schema],
- '$isArraySubdocument': true,
- events: [EventEmitter],
- _events: undefined,
- _eventsCount: 0,
- _maxListeners: undefined,
- setMaxListeners: [Function: setMaxListeners],
- getMaxListeners: [Function: getMaxListeners],
- emit: [Function: emit],
- addListener: [Function: addListener],
- on: [Function: addListener],
- prependListener: [Function: prependListener],
- once: [Function: once],
- prependOnceListener: [Function: prependOnceListener],
- removeListener: [Function: removeListener],
- off: [Function: removeListener],
- removeAllListeners: [Function: removeAllListeners],
- listeners: [Function: listeners],
- rawListeners: [Function: rawListeners],
- listenerCount: [Function: listenerCount],
- eventNames: [Function: eventNames],
- options: [Object],
- path: 'reviews',
- base: [Mongoose],
- '$appliedMethods': true,
- '$appliedHooks': true,
- _middleware: [Kareem] } },
- _handlers: { isNew: [Function: notify], save: [Function: notify] } ]
Add Comment
Please, Sign In to add comment