diff --git a/package.json b/package.json index 70f1c859..2d11317c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cadt", - "version": "1.7.1", + "version": "1.7.2", "_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2", "private": true, "bin": "build/server.js", diff --git a/src/controllers/organization.controller.js b/src/controllers/organization.controller.js index b50e8981..9550612f 100644 --- a/src/controllers/organization.controller.js +++ b/src/controllers/organization.controller.js @@ -1,6 +1,5 @@ import { Sequelize } from 'sequelize'; import { sequelize } from '../database'; -import { Organization } from '../models/organizations'; import datalayer from '../datalayer'; import { @@ -13,7 +12,7 @@ import { import { getDataModelVersion } from '../utils/helpers'; -import { ModelKeys, Audit, Staging } from '../models'; +import { ModelKeys, Audit, Organization, Staging } from '../models'; export const findAll = async (req, res) => { return res.json(await Organization.getOrgsMap()); @@ -21,17 +20,21 @@ export const findAll = async (req, res) => { export const homeOrgSyncStatus = async (req, res) => { try { - await assertHomeOrgExists(); + //await assertHomeOrgExists(); const walletSynced = await datalayer.walletIsSynced(); const homeOrg = await Organization.getHomeOrg(); + const pendingCommitsCount = await Staging.count({ + where: { commited: true }, + }); return res.json({ + ready: + walletSynced && Boolean(homeOrg?.synced) && pendingCommitsCount === 0, status: { wallet_synced: walletSynced, - home_org_synced: homeOrg?.synced ?? false, + home_org_synced: Boolean(homeOrg?.synced), + pending_commits: pendingCommitsCount, }, - message: - 'After you detect that wallet is synced, you will want to wait about 5 seconds and call this endpoint again to get the home org status. There is a delay between when the wallet is synced and when the proper status for home org is picked up.', success: true, }); } catch (error) { diff --git a/src/models/organizations/organizations.model.js b/src/models/organizations/organizations.model.js index d8cf9971..fd1aee87 100644 --- a/src/models/organizations/organizations.model.js +++ b/src/models/organizations/organizations.model.js @@ -9,7 +9,7 @@ import { sequelize } from '../../database'; import datalayer from '../../datalayer'; import { logger } from '../../config/logger.cjs'; -import { FileStore } from '../'; +import { FileStore, Staging } from '../'; import { getDefaultOrganizationList } from '../../utils/data-loaders'; @@ -48,7 +48,12 @@ class Organization extends Model { } if (myOrganization) { - myOrganization.synced = myOrganization.synced === 1; + const pendingCommitsCount = await Staging.count({ + where: { commited: true }, + }); + + myOrganization.synced = + myOrganization.synced === 1 && pendingCommitsCount === 0; } return myOrganization; @@ -74,6 +79,13 @@ class Organization extends Model { await datalayer.getPublicAddress(); organizations[i].dataValues.balance = await datalayer.getWalletBalance(); + + const pendingCommitsCount = await Staging.count({ + where: { commited: true }, + }); + + organizations[i].dataValues.synced = + organizations[i].dataValues.synced === 1 && pendingCommitsCount === 0; break; } }