Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const requestSchema = new Schema({
- ownerId: {
- type: Schema.ObjectId,
- ref: 'User'
- },
- petId: {
- type: Schema.ObjectId,
- ref: 'Pet'
- }
- }
- export const create = ({ user, bodymen: { body } }, res, next) =>
- Request.create({...body, ownerId: user})
- .then((request) => request.view(true))
- .then(success(res, 201))
- .catch(next)
- export const index = ({ querymen: { query, select, cursor } }, res, next) =>
- Request.count(query)
- .then(count => Request.find(query, select, cursor)
- .populate('ownerId', 'name')
- .populate('petId', 'name race')
- .exec()
- .then((requests) => ({
- count,
- rows: requests.map((request) => request.view())
- }))
- )
- .then(success(res))
- .catch(next)
- router.post('/',
- token({ required: true, roles: ['user'] }),
- body({ petId }),
- create)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement