Last active
February 29, 2016 16:23
-
-
Save thebergamo/aa4321047b81e8abb301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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