diff --git a/.gitignore b/.gitignore index e3c221e..7cd795c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.sublime-workspace *settings.json +.idea/* README-private.md npm-debug.log @@ -7,4 +8,4 @@ node_modules .DS_Store /**/.DS_Store -.demeteorized/ \ No newline at end of file +.demeteorized/ diff --git a/both/collections/users.js b/both/collections/users.js index bfc12aa..9b12fce 100644 --- a/both/collections/users.js +++ b/both/collections/users.js @@ -53,6 +53,10 @@ UserSchema = new SimpleSchema({ optional: true, blackbox: true }, + interestedInJobIds:{ + type:[String], + optional:true + }, roles: { type: Array, optional: true diff --git a/both/lib/methods.js b/both/lib/methods.js index 3deb035..921b747 100644 --- a/both/lib/methods.js +++ b/both/lib/methods.js @@ -23,6 +23,36 @@ Meteor.methods({ } }); }, + registerJobInterest: function(jobId) { + check(jobId, String); + + var job = Jobs.findOne({ + _id: jobId + }); + + if (!job) + throw new Meteor.Error("Could not find job."); + + if (job.status !== "active") + throw new Meteor.Error("You can only show interest in an active job."); + + var userProfile = Profiles.findOne({ + userId: this.userId + }); + + if ( !userProfile ) + throw new Meteor.Error("You must have a developer profile to register interest in a job."); + + Meteor.call("sendJobInterestEmail", job); + + Users.update({ + _id: this.userId + }, { + $addToSet: { + interestedInJobIds: jobId + } + }); + }, adminSetJobStatus: function(jobId, status) { check(jobId, String); check(status, String); diff --git a/client/views/jobs/job.html b/client/views/jobs/job.html index 799b4da..5df23f9 100644 --- a/client/views/jobs/job.html +++ b/client/views/jobs/job.html @@ -51,6 +51,16 @@


Featured Until {{formatDate featuredThrough}} {{/if}} + {{#if currentUser }} + {{#if $eq status "active" }} +
+ {{#if interestedIn }} + The owner of this post has been notified of your interest. + {{else}} + I'm interested in this + {{/if}} + {{/if}} + {{/if}}
{{#if htmlDescription}} diff --git a/client/views/jobs/job.js b/client/views/jobs/job.js index ec424b7..4530b00 100644 --- a/client/views/jobs/job.js +++ b/client/views/jobs/job.js @@ -2,11 +2,27 @@ Template.job.events({ 'click #job-deactivate': function(event, template) { event.preventDefault(); Modal.show('jobDeactivate', template.data); + }, + + 'click #im-interested': function(event, template) { + event.preventDefault(); + + Meteor.call("registerJobInterest", template.data._id, function(error, result) { + //Modal.hide("jobDeactivate"); + }); } }); Template.job.helpers({ 'hasLabel': function() { return this.jobType || this.remote || this.featured; + }, + + 'interestedIn': function () { + if ( Meteor.user().interestedInJobIds ) { + return Meteor.user().interestedInJobIds.includes(this._id) + } else { + return false; + } } }); diff --git a/server/lib/methods.js b/server/lib/methods.js new file mode 100644 index 0000000..ed912e8 --- /dev/null +++ b/server/lib/methods.js @@ -0,0 +1,24 @@ +Meteor.methods({ + sendJobInterestEmail: function(job) { + var userName = getUserName(Users.findOne({ + _id: this.userId + })); + + var jobOwnerEmail = getUserEmail(Users.findOne({ + _id: job.userId + })); + + var profile = Profiles.findOne({ + userId: this.userId + }); + + Email.send({ + to: jobOwnerEmail, + from: FROM_EMAIL, + subject: userName + " is interested in your job posting!", + text: userName + " is interested in your job posting at:\n\n" + Meteor.absoluteUrl("jobs/" + job._id) + + "\n\nCheck out their profile at:\n\n" + Meteor.absoluteUrl("profiles/" + profile._id) + }); + } + +})