Allow firstSyncCompletion to be null

This commit is contained in:
Ben Gotow 2016-07-12 15:04:12 -07:00
parent 84d8979265
commit dfa16fb5fc
2 changed files with 7 additions and 3 deletions

View file

@ -12,7 +12,11 @@ module.exports = (sequelize, Sequelize) => {
connectionCredentials: Sequelize.TEXT,
syncPolicy: JSONType('syncPolicy'),
syncError: JSONType('syncError', {defaultValue: null}),
firstSyncCompletion: Sequelize.INTEGER(14),
firstSyncCompletion: {
type: Sequelize.INTEGER(14),
allowNull: true,
defaultValue: null,
},
lastSyncCompletions: JSONARRAYType('lastSyncCompletions'),
}, {
classMethods: {

View file

@ -208,12 +208,12 @@ class SyncWorker {
onSyncDidComplete() {
const {afterSync} = this._account.syncPolicy;
const now = Date.now();
if (!this._account.firstSyncCompletion) {
this._account.firstSyncCompletion = Date.now()
this._account.firstSyncCompletion = now;
}
const now = Date.now();
const syncGraphTimeLength = 60 * 30; // 30 minutes, should be the same as SyncGraph.config.timeLength
let lastSyncCompletions = [].concat(this._account.lastSyncCompletions)
lastSyncCompletions = [now, ...lastSyncCompletions]