Skip to content

Instantly share code, notes, and snippets.

@joshbedo
Created June 1, 2017 22:01
Show Gist options
  • Save joshbedo/1d131351fa0ab82232101fcb9ec21646 to your computer and use it in GitHub Desktop.
Save joshbedo/1d131351fa0ab82232101fcb9ec21646 to your computer and use it in GitHub Desktop.
Checkout Routes
import Joi from 'joi';
import routePrerequisites from './routePrerequisites';
// Data schemas
import {CheckoutSerializer} from './serializers';
// API endpoint handlers
import {
CheckoutsHandler,
CheckoutIdHandler
} from './handlers';
/**
* API endpoints
*/
export default [
{
path: '',
method: 'POST',
config: {
handler: {async: CheckoutsHandler.post},
auth: {
mode: 'try',
strategy: 'jwt'
},
description: 'Create a new checkout',
tags: ['api'],
validate: {
headers: Joi.object({
'authorization': Joi.string().optional()
}).unknown(),
payload: {
cartId: Joi.string().required(),
billingAddress: Joi.object().optional()
}
},
response: {
schema: CheckoutSerializer.schema
}
}
},
{
path:'/{checkoutId}',
method: 'GET',
config: {
handler: {async: CheckoutIdHandler.get},
auth: {
mode: 'try',
strategy: 'jwt'
},
description: 'Get checkout',
notes: 'Returns a checkout by id passed in the path',
tags: ['api'],
pre: [routePrerequisites.validCheckoutAndPermissions],
validate: {
headers: Joi.object({
'authorization': Joi.string().optional()
}).unknown(),
params: {
checkoutId: Joi.string().required().description('the id for the checkout'),
}
},
response: {
schema: CheckoutSerializer.schema
}
}
},
{
path: '/{checkoutId}',
method: 'PATCH',
config: {
handler: {async: CheckoutIdHandler.patch},
auth: {
mode: 'try',
strategy: 'jwt'
},
description: 'Update checkout',
tags: ['api'],
pre: [routePrerequisites.validCheckoutAndPermissions],
validate: {
headers: Joi.object({
'authorization': Joi.string().optional()
}).unknown(),
params: {
checkoutId: Joi.string().required().description('the id for the checkout'),
}
},
response: {
schema: CheckoutSerializer.schema
}
}
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment