[n1] fix(api): Add support for messages?thread_id=1

This commit is contained in:
Ben Gotow 2016-11-23 16:25:45 -08:00
parent 42e20f106c
commit dd28d6b146

View file

@ -13,6 +13,7 @@ module.exports = (server) => {
tags: ['messages'],
validate: {
query: {
thread_id: Joi.string(),
limit: Joi.number().integer().min(1).max(2000).default(100),
offset: Joi.number().integer().min(0).default(0),
},
@ -26,9 +27,14 @@ module.exports = (server) => {
handler: (request, reply) => {
request.getAccountDatabase().then((db) => {
const {Message, Folder, Label} = db;
const wheres = {};
if (request.query.thread_id) {
wheres.threadId = request.query.thread_id;
}
Message.findAll({
limit: request.query.limit,
offset: request.query.offset,
where: wheres,
include: [{model: Folder}, {model: Label}],
}).then((messages) => {
reply(Serialization.jsonStringify(messages));