Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. const requestSchema = new Schema({
  2. ownerId: {
  3. type: Schema.ObjectId,
  4. ref: 'User'
  5. },
  6. petId: {
  7. type: Schema.ObjectId,
  8. ref: 'Pet'
  9. }
  10. }
  11.  
  12. export const create = ({ user, bodymen: { body } }, res, next) =>
  13. Request.create({...body, ownerId: user})
  14. .then((request) => request.view(true))
  15. .then(success(res, 201))
  16. .catch(next)
  17.  
  18. export const index = ({ querymen: { query, select, cursor } }, res, next) =>
  19. Request.count(query)
  20. .then(count => Request.find(query, select, cursor)
  21. .populate('ownerId', 'name')
  22. .populate('petId', 'name race')
  23. .exec()
  24. .then((requests) => ({
  25. count,
  26. rows: requests.map((request) => request.view())
  27. }))
  28. )
  29. .then(success(res))
  30. .catch(next)
  31.  
  32. router.post('/',
  33. token({ required: true, roles: ['user'] }),
  34. body({ petId }),
  35. create)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement