2016-06-29 09:14:39 +08:00
|
|
|
const Serialization = require('./serialization');
|
2016-06-29 06:35:35 +08:00
|
|
|
const {PubsubConnector, MessageTypes} = require('nylas-core')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
createSyncbackRequest: function createSyncbackRequest(request, reply, syncRequestArgs) {
|
|
|
|
request.getAccountDatabase().then((db) => {
|
|
|
|
db.SyncbackRequest.create(syncRequestArgs).then((syncbackRequest) => {
|
2016-07-01 04:25:13 +08:00
|
|
|
PubsubConnector.notifyAccount(db.accountId, {
|
2016-06-29 06:35:35 +08:00
|
|
|
type: MessageTypes.SYNCBACK_REQUESTED,
|
|
|
|
data: syncbackRequest.id,
|
|
|
|
});
|
|
|
|
reply(Serialization.jsonStringify(syncbackRequest))
|
|
|
|
})
|
|
|
|
})
|
2016-06-29 09:43:53 +08:00
|
|
|
},
|
2016-07-01 06:23:34 +08:00
|
|
|
findFolderOrLabel: function findFolderOrLabel({Folder, Label}, str) {
|
|
|
|
return Promise.props({
|
|
|
|
folder: Folder.find({
|
|
|
|
where: { $or: [
|
|
|
|
{ id: str },
|
|
|
|
{ name: str },
|
|
|
|
{ role: str },
|
|
|
|
]},
|
|
|
|
}),
|
|
|
|
label: Label.find({
|
|
|
|
where: { $or: [
|
|
|
|
{ id: str },
|
|
|
|
{ name: str },
|
|
|
|
{ role: str },
|
|
|
|
]},
|
|
|
|
}),
|
|
|
|
}).then(({folder, label}) =>
|
|
|
|
folder || label || null
|
|
|
|
)
|
|
|
|
},
|
2016-06-29 06:35:35 +08:00
|
|
|
}
|