Skip to content

Commit

Permalink
feat: update home status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Dec 1, 2023
1 parent ca18679 commit 230ab38
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 9 additions & 6 deletions src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Sequelize } from 'sequelize';
import { sequelize } from '../database';
import { Organization } from '../models/organizations';
import datalayer from '../datalayer';

import {
Expand All @@ -13,25 +12,29 @@ 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());
};

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) {
Expand Down
16 changes: 14 additions & 2 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 230ab38

Please sign in to comment.