fix sync double initialization issue

This commit is contained in:
azivner 2018-09-11 10:01:40 +02:00
parent e8797a137f
commit 9b425025c9
3 changed files with 9 additions and 8 deletions

View File

@ -6,7 +6,8 @@ const log = require('../../services/log');
async function getStatus() { async function getStatus() {
return { return {
isInitialized: await sqlInit.isDbInitialized() isInitialized: await sqlInit.isDbInitialized(),
schemaExists: await sqlInit.schemaExists()
}; };
} }

View File

@ -6,10 +6,10 @@ const repository = require('./repository');
const optionService = require('./options'); const optionService = require('./options');
const syncOptions = require('./sync_options'); const syncOptions = require('./sync_options');
async function isSyncServerInitialized() { async function hasSyncServerSchemaAndSeed() {
const response = await requestToSyncServer('GET', '/api/setup/status'); const response = await requestToSyncServer('GET', '/api/setup/status');
return response.isInitialized; return response.schemaExists;
} }
function triggerSync() { function triggerSync() {
@ -23,7 +23,7 @@ function triggerSync() {
}); });
} }
async function setupSyncToSyncServer() { async function sendSeedToSyncServer() {
log.info("Initiating sync to server"); log.info("Initiating sync to server");
await requestToSyncServer('POST', '/api/setup/sync-seed', { await requestToSyncServer('POST', '/api/setup/sync-seed', {
@ -105,9 +105,9 @@ async function getSyncSeedOptions() {
} }
module.exports = { module.exports = {
isSyncServerInitialized, hasSyncServerSchemaAndSeed,
triggerSync, triggerSync,
setupSyncToSyncServer, sendSeedToSyncServer,
setupSyncFromSyncServer, setupSyncFromSyncServer,
getSyncSeedOptions getSyncSeedOptions
}; };

View File

@ -71,8 +71,8 @@ async function sync() {
async function login() { async function login() {
const setupService = require('./setup'); // circular dependency issue const setupService = require('./setup'); // circular dependency issue
if (!await setupService.isSyncServerInitialized()) { if (!await setupService.hasSyncServerSchemaAndSeed()) {
await setupService.setupSyncToSyncServer(); await setupService.sendSeedToSyncServer();
} }
return await doLogin(); return await doLogin();