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

39 lines
1 KiB
JavaScript
Raw Normal View History

2016-06-23 05:17:45 +08:00
const Joi = require('joi');
const Serialization = require('../serialization');
module.exports = (server) => {
['folders', 'labels'].forEach((term) => {
server.route({
method: 'GET',
path: `/${term}`,
config: {
description: `${term}`,
notes: 'Notes go here',
tags: [term],
validate: {
query: {
limit: Joi.number().integer().min(1).max(2000).default(100),
offset: Joi.number().integer().min(0).default(0),
},
},
response: {
schema: Joi.array().items(
Serialization.jsonSchema('Category')
),
},
},
handler: (request, reply) => {
request.getAccountDatabase().then((db) => {
const {Category} = db;
Category.findAll({
limit: request.query.limit,
offset: request.query.offset,
}).then((categories) => {
reply(Serialization.jsonStringify(categories));
})
})
},
});
});
};