Pets
Functionality for dealing with pets
Markdown is supported in the extendedDescription
fields so
it is an ideal place to add additional information while leaving
the friendlyName
and description
fields concise. This allows
easier navigation and better collapsing of groups and routes.
- Donec et mollis dolor.
- Praesent et diam eget libero egestas mattis sit amet vitae augue.
- Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
- Donec ut libero sed arcu vehicula ultricies a non tortor.
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Add pet
post/pet
Add a new pet to the store
Body: Petjson
id | number | |
name | string * | |
category | object | |
tags | array | |
photoUrls | array * | |
status | string | pet status in the store |
Handler
*handler() { const pet = this.request.body; return yield this.db().table('pets').insert(pet).run(); }
Update pet
put/pet
Update an existing pet
Body: Petjson
id | number | |
name | string * | |
category | object | |
tags | array | |
photoUrls | array * | |
status | string | pet status in the store |
Handler
*handler() { const pet = this.request.body; if (!pet.id) this.throw(400, 'Invalid ID supplied'); const existing = this.db().get(pet.id).run(); if (!existing) this.throw(404, 'Pet not found'); return this.db().table('pets').update(pet).run(); }
Find pets by status
put/pet
Query
status | array | Status values that need to be considered for filter |
Output: Array [ Pet ]
id | number * | |
name | string * | |
category | object | |
tags | array | |
photoUrls | array * | |
status | string * | pet status in the store |
Handler
*handler() { const query = this.request.query; return yield this.db() .table('pets') .getAll(query.status) .run(); }
Store
Store inventory
get/store/inventory
Returns pet inventories by status
Implementation notes
- Returns a map of status codes to quantities
Output
available | number | Pets available for sale |
pending | number | # of pets awaiting processing |
sold | number | # of pets sold |
Handler
*handler() { // This route does not have any validations return this.db().table('store') .groupBy('statusCode') .map('quantity') .run(); }
Place an order for a pet
post/store/order
Body: Orderjson
id | number | |
petId | number | |
quantity | number | |
shipDate | date | |
status | string | |
complete | boolean |
Handler
*handler() { const order = this.request.body; yield this.db().table('orders').insert(order).run(); }