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

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-06-19 18:02:32 +08:00
const Serialization = require('../serialization');
const {DatabaseConnector} = require('nylas-core');
2016-06-19 18:02:32 +08:00
module.exports = (server) => {
server.route({
method: 'GET',
path: '/account',
config: {
description: 'Returns the current account.',
notes: 'Notes go here',
tags: ['accounts'],
validate: {
params: {
},
},
response: {
schema: Serialization.jsonSchema('Account'),
},
},
handler: (request, reply) => {
const account = request.auth.credentials;
reply(Serialization.jsonStringify(account));
},
});
server.route({
method: 'DELETE',
path: '/account',
config: {
description: 'Deletes the current account and all data from the Nylas Cloud.',
notes: 'Notes go here',
tags: ['accounts'],
validate: {
params: {
},
},
},
handler: (request, reply) => {
const account = request.auth.credentials;
account.destroy().then((saved) =>
DatabaseConnector.destroyAccountDatabase(saved.id).then(() =>
reply(Serialization.jsonStringify({status: 'success'}))
)
).catch((err) => {
reply(err).code(500);
})
},
});
2016-06-19 18:02:32 +08:00
};