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

idnumber
namestring *
categoryobject
tagsarray
photoUrlsarray *
statusstringpet 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

idnumber
namestring *
categoryobject
tagsarray
photoUrlsarray *
statusstringpet 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

statusarrayStatus values that need to be considered for filter

Output: Array [ Pet ]

idnumber *
namestring *
categoryobject
tagsarray
photoUrlsarray *
statusstring *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

availablenumberPets available for sale
pendingnumber# of pets awaiting processing
soldnumber# 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

idnumber
petIdnumber
quantitynumber
shipDatedate
statusstring
completeboolean

Handler

*handler() {
   const order = this.request.body;
   yield this.db().table('orders').insert(order).run();
}