Skip to content

Instantly share code, notes, and snippets.

@thebergamo
Last active February 29, 2016 16:23
Show Gist options
  • Save thebergamo/aa4321047b81e8abb301 to your computer and use it in GitHub Desktop.
Save thebergamo/aa4321047b81e8abb301 to your computer and use it in GitHub Desktop.
// [GET] /category
function list (request, reply) {
this.model
.scope({
method: ['user', request.auth.credentials.id]
})
.findAndCountAll({
attributes: ['id', 'description'],
order: 'description',
offset: request.offset,
limit: request.limit,
where: {
$and: this.search(request)
}
})
.then((result) => {
reply({
data: result.rows,
count: result.count
});
}).catch((err) => reply.badImplementation(err.message));
}
let page = this.query.page || 0;
const limit = 10;
const offset = limit * (page - 1);
server.decorate('request', 'offset', offset);
server.decorate('request', 'limit', limit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment