Skip to content

Commit

Permalink
Merge pull request #570 from Chia-Network/fix/pending-organization-fix
Browse files Browse the repository at this point in the history
fix: add and clean up temp records to the database on org creation
  • Loading branch information
MichaelTaylor3D authored May 30, 2022
2 parents 4314416 + 2079767 commit 53d1682
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ class Organization extends Model {
return myOrganization.orgUid;
}

await Organization.create({
orgUid: 'PENDING',
registryId: null,
isHome: true,
subscribed: false,
name: '',
icon: '',
});

const newOrganizationId = USE_SIMULATOR
? 'f1c54511-865e-4611-976c-7c3c1f704662'
: await datalayer.createDataLayerStore();
Expand All @@ -76,7 +85,10 @@ class Organization extends Model {

const revertOrganizationIfFailed = async () => {
logger.info('Reverting Failed Organization');
await Organization.destroy({ where: { orgUid: newOrganizationId } });
await Promise.all([
Organization.destroy({ where: { orgUid: newOrganizationId } }),
Organization.destroy({ where: { orgUid: 'PENDING' } }),
]);
};

// sync the organization store
Expand All @@ -99,14 +111,17 @@ class Organization extends Model {
revertOrganizationIfFailed,
);

await Organization.create({
orgUid: newOrganizationId,
registryId: registryVersionId,
isHome: true,
subscribed: USE_SIMULATOR,
name,
icon,
});
await Promise.all([
Organization.create({
orgUid: newOrganizationId,
registryId: registryVersionId,
isHome: true,
subscribed: USE_SIMULATOR,
name,
icon,
}),
Organization.destroy({ where: { orgUid: 'PENDING' } }),
]);

const onConfirm = () => {
logger.info('Organization confirmed, you are ready to go');
Expand Down

0 comments on commit 53d1682

Please sign in to comment.