Fixes to sync worker

This commit is contained in:
Evan Morikawa 2016-06-28 15:44:29 -07:00
parent ca0120a824
commit 2d90c5bb14

View file

@ -52,13 +52,17 @@ class SyncWorker {
} }
_onAccountUpdated() { _onAccountUpdated() {
console.log("SyncWorker: Detected change to account. Reloading and syncing now.") console.log("SyncWorker: Detected change to account. Reloading and syncing now.");
DatabaseConnector.forShared().then(({Account}) => { this._getAccount().then((account) => {
Account.find({where: {id: this._account.id}}).then((account) => { this._account = account;
this._account = account; this.syncNow();
this.syncNow(); })
}) }
});
_getAccount() {
return DatabaseConnector.forShared().then(({Account}) =>
Account.find({where: {id: this._account.id}})
);
} }
onSyncDidComplete() { onSyncDidComplete() {
@ -122,16 +126,15 @@ class SyncWorker {
} }
syncbackMessageActions() { syncbackMessageActions() {
const {SyncbackRequest, accountId, Account} = this._db; return this._getAccount((account) =>
return this._db.Account.find({where: {id: accountId}}).then((account) => { Promise.each(this._db.SyncbackRequest.findAll().then((reqs = []) =>
return Promise.each(SyncbackRequest.findAll().then((reqs = []) =>
reqs.map((request) => { reqs.map((request) => {
const task = SyncbackTaskFactory.create(account, request); const task = SyncbackTaskFactory.create(account, request);
if (!task) return Promise.reject("No Task") if (!task) return Promise.reject("No Task")
return this._conn.runOperation(task) return this._conn.runOperation(task)
}) })
)); ))
}); )
} }
syncAllCategories() { syncAllCategories() {