/*prepopulates db with user's testing data if it's empty
and app is in development mode.*/

let mode = process.env.NODE_ENV;

Meteor.startup(function() {
  if (mode != 'development') return;
  YAML.eval(Assets.getText('users.yml')).users.forEach(user => {
    if (Meteor.users.find({'username': user.username}).count() > 0) return;

    let milestones = YAML.eval(Assets.getText('milestones.yml')).milestones;
    let goals = YAML.eval(Assets.getText('goals.yml')).goals;

    let userId = Accounts.createUser(user);
    let milestoneId = null;

    milestones.forEach(milestone => {
      milestoneData = _.extend(milestone, {userId, parentId: milestoneId});
      milestoneId = Milestones.insert(milestoneData);

      goals.forEach(goal => {
        Goals.insert(_.extend(goal, {userId, milestoneId}));
      });
    })
  });
});

@@ -1,10 +1,11 @@
 /*
+ 
 prepopul
@@ -82,16 +82,17 @@
 nt mode.
+ 
 */%0A%0Alet 
@@ -162,16 +162,17 @@
 (mode !=
+=
  'develo
@@ -540,16 +540,39 @@
  = null;
+%0A    let goalId = null;
 %0A%0A    mi
@@ -658,16 +658,17 @@
 Id, 
+'
 parentId
 : mi
@@ -663,16 +663,17 @@
 parentId
+'
 : milest
@@ -778,21 +778,19 @@
     
-Goals.insert(
+goalData = 
 _.ex
@@ -820,18 +820,78 @@
 estoneId
-%7D)
+, 'parentId': goalId%7D);%0A        goalId = Goals.insert(goalData
 );%0A     
@@ -895,22 +895,23 @@
     %7D);%0A
-
     %7D)
+;
 %0A  %7D);%0A%7D

add parent-child relations between goals