Jobs = new Mongo.Collection('jobs'); //both on client and server
Applications = new Mongo.Collection('applications');

// added repoz channel

Meteor.startup(function() {
  // console.log('Jobs.remove({})');
  // Jobs.remove({});
  if (Jobs.find({}).count() === 0) {
    console.log('job count === ', Jobs.find({}).count(), 'inserting jobs');
    Jobs.insert({_id: '0', title: 'Select a job position...'});
    Jobs.insert({_id: '1', title: 'Haiti Village Photographer'});
    Jobs.insert({_id: '2', title: 'Rapallo On The Beach'});
  } else {
    console.log('server/getreel.js:', 'job count > 0 (', Jobs.find({}).count(), '): no insert needed');
  }
});

Meteor.methods({
  apply: function(args) {
    if (!Meteor.userId()) {
      throw new Meteor.Error('not-authorized');
    }

    console.log(args);

    Applications.insert({
      createdAt: new Date(),
      applicant: Meteor.userId(),
      firstname: args.firstname,
      lastname: args.lastname,
      job: args.job,
      resume: args.resume,
      videofile: args.videofile,
      videolink: args.videolink
    });
  }
});

Jobs = new Mongo.Collection('jobs'); //both on client and server
Applications = new Mongo.Collection('applications');

// added repoz channel

Meteor.startup(function() {
  // console.log('Jobs.remove({})');
  // Jobs.remove({});
  var jobCount = Jobs.find({}).count();
  if (jobCount === 0) {
    console.log('job count === ', jobCount, 'inserting jobs');
    Jobs.insert({_id: '0', title: 'Select a job position...'});
    Jobs.insert({_id: '1', title: 'Haiti Village Photographer'});
    Jobs.insert({_id: '2', title: 'Rapallo On The Beach'});
  } else {
    console.log('server/getreel.js:', 'job count > 0 (', jobCount, '): no insert needed');
  }
});

Meteor.methods({
  apply: function(args) {
    if (!Meteor.userId()) {
      throw new Meteor.Error('not-authorized');
    }

    console.log(args);

    Applications.insert({
      createdAt: new Date(),
      applicant: Meteor.userId(),
      firstname: args.firstname,
      lastname: args.lastname,
      job: args.job,
      resume: args.resume,
      videofile: args.videofile,
      videolink: args.videolink
    });
  }
});

Improve flexibility, readability and performance
Improve flexibility, readability and performance

Extracting the operation of counting jobs into a single variable has many
advantages:
1. Flexibility: it's easier now to modify the statement and be sure that the
change will be propagated to the rest of the code
2. Readability: reading 'jobCount' inside an algorithm is much more readable
than 'Jobs.find({}).count()'
3. Performance: you just make one call to the database and then store the result,
which is not going to change throughout this code.
