Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const t = require('koa-joi-router').Joi;
const Category = t.object().label('Category').keys({
id: t.number(),
name: t.string()
});
const Tag = t.object().label('Tag').keys({
id: t.number(),
name: t.string()
});
const Pet = t.object().label('Pet').keys({
id: t.number().optional(),
name: t.string().required(),
category: Category,
tags: t.array().items(Tag),
photoUrls: t.array().items(t.string()).required(),
status: t.string()
.valid(['available', 'pending', 'sold'])
.description('pet status in the store')
});
const createPet = {
method: 'post',
path: '/pet',
meta: {
friendlyName: 'Add pet',
description: 'Add a new pet to the store'
method: 'get',
path: '/alerts',
handler: async (ctx: Context) => ctx.body = { alerts: this.app.alerts.getAlerts() }
})
router.route({
method: 'get',
path: '/balance',
handler: async (ctx: Context) => ctx.body = this.app.getBalances()
})
router.route({
method: 'post',
path: '/peer',
validate: {
body: {
peerInfo: Joi.object().required(),
endpointInfo: Joi.object().required()
},
type: 'json'
},
handler: async (ctx: Context) => {
const peerInfo = ctx.request.body['peerInfo']
const endpointInfo = ctx.request.body['endpointInfo']
await this.app.addPeer(peerInfo, endpointInfo, true)
await this._auth.generateAuthToken(peerInfo.id)
ctx.response.status = 204
}
})
router.route({
method: 'get',
path: '/peer',
handler: async (ctx: Context) => ctx.body = this.app.connector.getPeerList()
})
* Returns a map of status codes to quantities
`
},
validate: {
output: {
200: {
body: {
available: Quantity.description('Pets available for sale'),
pending: Quantity.description('# of pets awaiting processing'),
sold: Quantity.description('# of pets sold')
}
},
400: {
body: {
code: t.number().integer().min(0).max(100).default(0).description('Code to explain the response.'),
errors: t.object().keys({
name: {
message: t.string().required().default('Some pet has no name!').description('Thrown when some pets has no name.')
}
}),
tags: t.array().items(t.object().keys({
label: t.string().example('Hello').example('World'),
signal: t.array().items(t.string())
})),
error: t.string().valid('Pets not found!').description('Pets not found!')
}
},
500: {
body: t.string().default('Server Internal Error.')
}
}
},
router.route({
method: 'get',
path: '/alerts',
handler: async (ctx: Context) => ctx.body = { alerts: this.app.alerts.getAlerts() }
})
router.route({
method: 'get',
path: '/balance',
handler: async (ctx: Context) => ctx.body = this.app.getBalances()
})
router.route({
method: 'post',
path: '/peer',
validate: {
body: {
peerInfo: Joi.object().required(),
endpointInfo: Joi.object().required()
},
type: 'json'
},
handler: async (ctx: Context) => {
const peerInfo = ctx.request.body['peerInfo']
const endpointInfo = ctx.request.body['endpointInfo']
await this.app.addPeer(peerInfo, endpointInfo, true)
await this._auth.generateAuthToken(peerInfo.id)
ctx.response.status = 204
}
})
router.route({
method: 'get',
path: '/peer',
handler: async (ctx: Context) => ctx.body = this.app.connector.getPeerList()
'use strict';
const t = require('koa-joi-router').Joi;
const Order = t.object().label('Order').keys({
id: t.number(),
petId: t.number(),
quantity: t.number(),
shipDate: t.date(),
status: t.string().valid(['placed', 'approved', 'delivered']),
complete: t.boolean()
});
const Quantity = t.number().integer().label('Quantity');
const storeInventory = {
method: 'get',
path: '/inventory',
meta: {
friendlyName: 'Store inventory',
description: 'Returns pet inventories by status',