Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
};
const getPetByStatus = {
method: 'put',
path: '/pet',
meta: {
friendlyName: 'Find pets by status'
},
validate: {
type: 'json',
query: {
status: t.array()
.description('Status values that need to be considered for filter')
.items(t.string())
.min(1) // At least 1 should be provided
.single() // If only one is provided, wrap it in an array
},
output: {
200: {
body: t.array().items(Pet.requiredKeys('id', 'status')),
header: {
'Content-Type': t.string()
}
}
}
},
*handler () {
const query = this.request.query;
return yield this.db()
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.')
}
}
},
*handler () {
// This route does not have any validations
return this.db().table('store')
.groupBy('statusCode')
.map('quantity')
.run();
}
};
const orderPet = {
method: 'post',
path: '/order',
meta: {
try {
const account = await accounts.get(ctx.request.params.id)
ctx.body = account
} catch (error) {
ctx.response.status = 404
}
}
})
middlewareRouter.route({
method: 'post',
path: '/peers',
validate: {
body: {
id: Joi.string().required(),
relation: Joi.string().required(),
url: Joi.string().optional()
},
type: 'json'
},
handler: async (ctx: Context) => {
const peerInfo = ctx.request.body
const peer = await peers.add(peerInfo)
// const account = await accounts.set()
// TODO: Do we create the token automatically
// await tokenService.create({ sub: peerInfo.id, active: true })
ctx.response.body = peer
ctx.response.status = 201
}
})
middlewareRouter.route({
method: 'get',
path: '/peers',
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.')
}
}
},
*handler () {
// This route does not have any validations
return this.db().table('store')
.groupBy('statusCode')
.map('quantity')
.run();
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.')
}
}
},
*handler () {
// This route does not have any validations
return this.db().table('store')
.groupBy('statusCode')
.map('quantity')
.run();
}
};
friendlyName: 'Find pets by status'
},
validate: {
type: 'json',
query: {
status: t.array()
.description('Status values that need to be considered for filter')
.items(t.string())
.min(1) // At least 1 should be provided
.single() // If only one is provided, wrap it in an array
},
output: {
200: {
body: t.array().items(Pet.requiredKeys('id', 'status')),
header: {
'Content-Type': t.string()
}
}
}
},
*handler () {
const query = this.request.query;
return yield this.db()
.table('pets')
.getAll(query.status)
.run();
}
};
module.exports = [
createPet,
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'
},
validate: {
const builder = (router, container) => {
router.route({
method: 'get',
path: '/search',
validate: {
query: {
term: Joi.string().min(1).max(255).required(),
from: Joi.number().min(0),
size: Joi.number().min(0),
effect: Joi.number().min(0),
weightQuality: Joi.number().min(0),
weightPopularity: Joi.number().min(0),
weightMaintenance: Joi.number().min(0),
},
},
handler: handler(container.elasticClient),
});
return router;
};
},
body: {
amount: Joi.string().required(),
scale: Joi.number().required()
},
type: 'json'
},
handler: createSettlement
})
router.route({
method: 'post',
path: '/accounts/:id/messages',
validate: {
params: {
id: Joi.string().required()
}
},
handler: createMessage
})
return router
}