From f94acfcb9bd395bee77d9def48bc2c4fd8bcedc8 Mon Sep 17 00:00:00 2001 From: Halla Moore Date: Thu, 30 Jun 2016 16:09:02 -0700 Subject: [PATCH] Added filename query to threads endpoint --- packages/nylas-api/routes/threads.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/nylas-api/routes/threads.js b/packages/nylas-api/routes/threads.js index 0c7ad8c36..ff799f22b 100644 --- a/packages/nylas-api/routes/threads.js +++ b/packages/nylas-api/routes/threads.js @@ -23,6 +23,7 @@ module.exports = (server) => { 'lastMessageBefore': Joi.date().timestamp(), 'lastMessageAfter': Joi.date().timestamp(), 'in': Joi.string().allow(Joi.number()), + 'filename': Joi.string(), 'limit': Joi.number().integer().min(1).max(2000).default(100), 'offset': Joi.number().integer().min(0).default(0), }, @@ -40,7 +41,7 @@ module.exports = (server) => { }, handler: (request, reply) => { request.getAccountDatabase().then((db) => { - const {Thread, Folder, Label, Message} = db; + const {Thread, Folder, Label, Message, File} = db; const query = request.query; const where = {}; const include = []; @@ -104,17 +105,26 @@ module.exports = (server) => { include.push({model: Label}) } + const messagesInclude = []; + if (query.filename) { + messagesInclude.push({ + model: File, + where: {filename: query.filename}, + }) + } if (query.view === 'expanded') { include.push({ model: Message, as: 'messages', attributes: _.without(Object.keys(Message.attributes), 'body'), + include: messagesInclude, }) } else { include.push({ model: Message, as: 'messages', attributes: ['id'], + include: messagesInclude, }) }