Ensure things exist for new workspaces (Closes #482)

This commit is contained in:
Gregory Schier 2017-09-13 07:40:11 +02:00
parent dae20dbe40
commit e6b97dc96c
2 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,7 @@
// @flow
import type {BaseModel} from './index';
import * as db from '../common/database';
import * as models from './index';
export const name = 'Workspace';
export const type = 'Workspace';
@ -46,8 +47,15 @@ export function getById (id: string): Promise<Workspace | null> {
return db.get(type, id);
}
export function create (patch: Object = {}): Promise<Workspace> {
return db.docCreate(type, patch);
export async function create (patch: Object = {}): Promise<Workspace> {
const workspace = await db.docCreate(type, patch);
// Make sure CookieJars and environments exist for all workspaces
// TODO: Find a better place to do this
await models.cookieJar.getOrCreateForParentId(workspace._id);
await models.environment.getOrCreateForWorkspace(workspace);
return workspace;
}
export async function all (): Promise<Array<Workspace>> {

View File

@ -21,12 +21,6 @@ import {isDevelopment} from '../common/constants';
await initAnalytics(getAccountId());
await initPlugins();
// Make sure CookieJars and environments exist for all workspaces
for (const workspace of await models.workspace.all()) {
await models.cookieJar.getOrCreateForParentId(workspace._id);
await models.environment.getOrCreateForWorkspace(workspace);
}
// Create Redux store
const store = await initStore();