Mailspring/packages/nylas-api/routes/threads.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-06-19 18:02:32 +08:00
const Joi = require('joi');
const Serialization = require('../serialization');
const {createSyncbackRequest} = require('../route-helpers')
2016-06-19 18:02:32 +08:00
module.exports = (server) => {
server.route({
method: 'GET',
path: '/threads',
config: {
description: 'Returns threads',
notes: 'Notes go here',
tags: ['threads'],
validate: {
params: {
},
},
response: {
schema: Joi.array().items(
2016-06-24 06:46:52 +08:00
Serialization.jsonSchema('Thread')
2016-06-19 18:02:32 +08:00
),
},
},
handler: (request, reply) => {
request.getAccountDatabase().then((db) => {
const {Thread} = db;
Thread.findAll({limit: 50}).then((threads) => {
reply(Serialization.jsonStringify(threads));
})
})
},
});
2016-06-24 06:46:52 +08:00
server.route({
method: 'PUT',
path: '/threads/${id}',
config: {
description: 'Update a thread',
notes: 'Can move between folders',
tags: ['threads'],
validate: {
params: {
payload: {
folder_id: Joi.string(),
},
},
},
response: {
schema: Joi.array().items(
Serialization.jsonSchema('Thread')
),
},
},
handler: (request, reply) => {
createSyncbackRequest(request, reply, {
type: "MoveToFolder",
props: {
folderId: request.params.folder_id,
threadId: requres.params.id,
}
2016-06-24 06:46:52 +08:00
})
},
});
2016-06-19 18:02:32 +08:00
};