/* 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;
    let goalId = null;
    let parentGoalIds = [];

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

      goals.forEach(goal => {
        let parentGoalIndex = parentGoalIds.length - 3;
        goalData = _.extend(goal, {userId, milestoneId,
                          'parentId': parentGoalIds[parentGoalIndex]});
        goalId = Goals.insert(goalData);
        parentGoalIds.push(goalId);
      });
    });
  });
});

@@ -283,17 +283,16 @@
 nd(%7B
-'
 username
 ': u
@@ -287,17 +287,16 @@
 username
-'
 : user.u
@@ -625,24 +625,101 @@
 estone =%3E %7B%0A
+      const bounds = Milestones.boundsFor(milestone.period, milestone.type);%0A
       milest
@@ -747,16 +747,24 @@
 lestone,
+ bounds,
  %7B userI
@@ -996,17 +996,16 @@
     
-'
 parentId
 ': p
@@ -1000,17 +1000,16 @@
 parentId
-'
 : parent

fix loading milestones seeds