Skip to content

Commit

Permalink
fix: dont mutate homeorg info if no homeorg
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Oct 24, 2023
1 parent 3f79378 commit b5f79c1
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 156 deletions.
141 changes: 59 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,32 @@
"assets": "package.json"
},
"dependencies": {
"@babel/eslint-parser": "^7.22.9",
"@babel/eslint-parser": "^7.22.15",
"async-mutex": "^0.4.0",
"body-parser": "^1.20.2",
"cli-spinner": "^0.2.10",
"cors": "^2.8.5",
"csvtojson": "^2.0.10",
"dotenv": "^16.0.3",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-joi-validation": "^5.0.1",
"joi": "^17.5.0",
"joi": "^17.11.0",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"log-update": "^4.0.0",
"multer": "*",
"multer": "^1.4.5-lts.1",
"mysql2": "^2.3.3",
"node-xlsx": "^0.23.0",
"regenerator-runtime": "^0.13.9",
"regenerator-runtime": "^0.13.11",
"rxjs": "^7.8.1",
"sequelize": "^6.32.0",
"socket.io": "^4.6.1",
"sequelize": "^6.33.0",
"socket.io": "^4.7.2",
"sqlite3": "^5.1.6",
"superagent": "^8.0.9",
"toad-scheduler": "^1.6.0",
"uuidv4": "^6",
"winston": "^3.7.2",
"winston-daily-rotate-file": "^4.6.1"
"superagent": "^8.1.2",
"toad-scheduler": "^3.0.0",
"uuidv4": "^6.2.13",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1"
},
"devDependencies": {
"@babel/cli": "^7.23.0",
Expand Down
30 changes: 17 additions & 13 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,23 @@ app.use(function (req, res, next) {
});

app.use(async function (req, res, next) {
// If the home organization is syncing, then we treat all requests as read-only
const homeOrg = await Organization.getHomeOrg();

if (req.method !== 'GET' && !homeOrg.synced) {
res.status(400).json({
message:
'Your organization data is still resyncing, please try again after it completes',
success: false,
});
} else if (homeOrg.synced) {
res.setHeader(headerKeys.HOME_ORGANIZATION_SYNCED, true);
} else {
res.setHeader(headerKeys.HOME_ORGANIZATION_SYNCED, false);
if (process.env.NODE_ENV !== 'test') {
// If the home organization is syncing, then we treat all requests as read-only
const homeOrg = await Organization.getHomeOrg();

if (homeOrg) {
if (req.method !== 'GET' && !homeOrg.synced) {
res.status(400).json({
message:
'Your organization data is still resyncing, please try again after it completes',
success: false,
});
} else if (homeOrg?.synced) {
res.setHeader(headerKeys.HOME_ORGANIZATION_SYNCED, true);
} else {
res.setHeader(headerKeys.HOME_ORGANIZATION_SYNCED, false);
}
}
}

next();
Expand Down
16 changes: 4 additions & 12 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ import ModelTypes from './organizations.modeltypes.cjs';
class Organization extends Model {
static async getHomeOrg(includeAddress = true) {
const myOrganization = await Organization.findOne({
attributes: [
'orgUid',
'name',
'icon',
'subscribed',
'registryId',
'fileStoreId',
'metadata',
'synced',
],
where: { isHome: true },
raw: true,
});
Expand All @@ -51,14 +41,16 @@ class Organization extends Model {
delete myOrganization.metadata;
}

myOrganization.synced = myOrganization?.synced === 1;

if (myOrganization && includeAddress) {
myOrganization.xchAddress = await datalayer.getPublicAddress();
myOrganization.fileStoreSubscribed = true;
return myOrganization;
}

if (myOrganization) {
myOrganization.synced = myOrganization.synced === 1;
}

return myOrganization;
}

Expand Down
Loading

0 comments on commit b5f79c1

Please sign in to comment.