Skip to content

Commit

Permalink
Merge pull request #1089 from ParabolInc/fix-914
Browse files Browse the repository at this point in the history
welcome wizard race condition Fix #914
  • Loading branch information
jordanh authored Jun 27, 2017
2 parents 126fa8b + 3200a47 commit e71d061
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/server/graphql/models/Team/createFirstTeam/createFirstTeam.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import {GraphQLID, GraphQLNonNull} from 'graphql';
import getRethink from 'server/database/rethinkDriver';
import {
ensureUniqueId,
requireAuth
} from 'server/utils/authorization';
import createNewOrg from 'server/graphql/models/Organization/addOrg/createNewOrg';
import {ensureUniqueId, requireAuth} from 'server/utils/authorization';
import {TRIAL_EXPIRES_SOON_DELAY} from 'server/utils/serverConstants';
import tmsSignToken from 'server/utils/tmsSignToken';
import {errorObj, handleSchemaErrors} from 'server/utils/utils';
import {
GraphQLNonNull,
GraphQLID
} from 'graphql';
import {TeamInput} from '../teamSchema';
import shortid from 'shortid';
import {TRIAL_EXPIRES_SOON} from 'universal/utils/constants';
import {TeamInput} from '../teamSchema';
import addSeedProjects from './addSeedProjects';
import createTeamAndLeader from './createTeamAndLeader';
import tmsSignToken from 'server/utils/tmsSignToken';
import createFirstTeamValidation from './createFirstTeamValidation';
import {TRIAL_EXPIRES_SOON} from 'universal/utils/constants';
import createNewOrg from 'server/graphql/models/Organization/addOrg/createNewOrg';
import {TRIAL_EXPIRES_SOON_DELAY} from 'server/utils/serverConstants';
import createTeamAndLeader from './createTeamAndLeader';

export default {
// return the new JWT that has the new tms field
Expand Down Expand Up @@ -66,15 +60,15 @@ export default {
const validNewTeam = {...data, orgId};
const {id: teamId} = validNewTeam;
const tms = [teamId];
const expiresSoonId = shortid.generate();
const orgName = `${user.preferredName}’s Org`;
const {periodEnd} = await createNewOrg(orgId, orgName, userId);
await createTeamAndLeader(userId, validNewTeam, true);
// set up the team while the user is on step 3
setTimeout(async () => {
const expiresSoonId = shortid.generate();
const orgName = `${user.preferredName}’s Org`;
const {periodEnd} = await createNewOrg(orgId, orgName, userId);
await createTeamAndLeader(userId, validNewTeam, true);
addSeedProjects(userId, teamId);
// Asynchronously create seed projects for team leader:
// TODO: remove me after more
addSeedProjects(userId, teamId);
await r.table('Notification').insert({
id: expiresSoonId,
type: TRIAL_EXPIRES_SOON,
Expand All @@ -84,7 +78,9 @@ export default {
// trialExpiresAt
varList: [periodEnd]
});
if (unitTestCb) { unitTestCb(); }
if (unitTestCb) {
unitTestCb();
}
}, 0);
return tmsSignToken(authToken, tms);
}
Expand Down

0 comments on commit e71d061

Please sign in to comment.