From ef0d738629b2e8de15c441049806bc7f3ca8068e Mon Sep 17 00:00:00 2001 From: chadnaylor Date: Sun, 20 Nov 2016 21:52:45 -0800 Subject: [PATCH 1/6] interestedInJobIds updates correctly --- .gitignore | 3 ++- both/collections/users.js | 4 ++++ both/lib/methods.js | 25 +++++++++++++++++++++++++ client/views/jobs/job.html | 5 ++++- client/views/jobs/job.js | 8 ++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) 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..06072bb 100644 --- a/both/lib/methods.js +++ b/both/lib/methods.js @@ -23,6 +23,31 @@ Meteor.methods({ } }); }, + registerJobInterest: function(jobId) { + check(jobId, String); + + var user = Users.findOne({ + _id: this.userId + }); + + + // if (!job) + // throw new Meteor.Error("Could not find job."); + // + // if (this.userId !== job.userId) + // throw new Meteor.Error("You can only deactivate your own job."); + // + // if (job.status !== "active") + // throw new Meteor.Error("You can only deactivate an active job."); + + Users.update({ + _id: this.userId + }, { + $set: { + 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..476d645 100644 --- a/client/views/jobs/job.html +++ b/client/views/jobs/job.html @@ -51,7 +51,10 @@


Featured Until {{formatDate featuredThrough}} {{/if}} - +
+ I'm interested! + +
{{#if htmlDescription}} {{{htmlDescription}}} diff --git a/client/views/jobs/job.js b/client/views/jobs/job.js index ec424b7..cf5ed1c 100644 --- a/client/views/jobs/job.js +++ b/client/views/jobs/job.js @@ -2,6 +2,14 @@ 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"); + }); } }); From 72ba87500f46cd306fff1fd518b9e278a064d9eb Mon Sep 17 00:00:00 2001 From: chadnaylor Date: Mon, 21 Nov 2016 01:30:09 -0800 Subject: [PATCH 2/6] interestedInJobIds has correct behaviour for interest in multiple jobs --- both/lib/helpers.js | 2 ++ both/lib/methods.js | 28 ++++++++++++++++------------ client/views/jobs/job.html | 7 +++++-- client/views/jobs/job.js | 8 ++++++++ server/hooks.js | 4 ++++ server/publications.js | 4 ++++ 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/both/lib/helpers.js b/both/lib/helpers.js index fb7ab00..ce877fc 100644 --- a/both/lib/helpers.js +++ b/both/lib/helpers.js @@ -37,3 +37,5 @@ daysUntilExpiration = function() { daysAgo.setDate(daysAgo.getDate() - daysToWait); return daysAgo; } + + diff --git a/both/lib/methods.js b/both/lib/methods.js index 06072bb..0545a6e 100644 --- a/both/lib/methods.js +++ b/both/lib/methods.js @@ -26,25 +26,29 @@ Meteor.methods({ registerJobInterest: function(jobId) { check(jobId, String); - var user = Users.findOne({ - _id: this.userId + var job = Jobs.findOne({ + _id: jobId }); + if (!job) + throw new Meteor.Error("Could not find job."); - // if (!job) - // throw new Meteor.Error("Could not find job."); - // - // if (this.userId !== job.userId) - // throw new Meteor.Error("You can only deactivate your own job."); - // - // if (job.status !== "active") - // throw new Meteor.Error("You can only deactivate an active 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."); Users.update({ _id: this.userId }, { - $set: { - interestedInJobIds: [jobId] + $push: { + interestedInJobIds: jobId } }); }, diff --git a/client/views/jobs/job.html b/client/views/jobs/job.html index 476d645..6af63a2 100644 --- a/client/views/jobs/job.html +++ b/client/views/jobs/job.html @@ -52,8 +52,11 @@

Featured Until {{formatDate featuredThrough}} {{/if}}
- I'm interested! - + {{#if notInterested }} + I'm interested in this + {{else}} + The owner of this post has been notified of your interest. + {{/if}}

{{#if htmlDescription}} diff --git a/client/views/jobs/job.js b/client/views/jobs/job.js index cf5ed1c..7d467ca 100644 --- a/client/views/jobs/job.js +++ b/client/views/jobs/job.js @@ -16,5 +16,13 @@ Template.job.events({ Template.job.helpers({ 'hasLabel': function() { return this.jobType || this.remote || this.featured; + }, + + 'notInterested': function () { + if ( Meteor.user().interestedInJobIds ) { + return !Meteor.user().interestedInJobIds.includes(this._id) + } else { + return true; + } } }); diff --git a/server/hooks.js b/server/hooks.js index 948050d..c608652 100644 --- a/server/hooks.js +++ b/server/hooks.js @@ -27,3 +27,7 @@ Jobs.after.insert(function(userId, doc) { text: "Job needs to be approved before it is live:\n\n" + Meteor.absoluteUrl("jobs/" + doc._id) + "\n\n\n\n\n\n" }); }); + +// Users.before.update(function(userId, doc) { +// +// }) diff --git a/server/publications.js b/server/publications.js index abd8a98..0ab185a 100644 --- a/server/publications.js +++ b/server/publications.js @@ -5,6 +5,10 @@ Meteor.publish(null, function () { return [ Users.find({ _id: this.userId + }, { + fields: { + interestedInJobIds: 1 + } }), Profiles.find({ userId: this.userId From e1394f0e7bbe8d584c3f76351094c7d771d76551 Mon Sep 17 00:00:00 2001 From: chadnaylor Date: Mon, 21 Nov 2016 03:39:22 -0800 Subject: [PATCH 3/6] email send works correctly --- both/lib/helpers.js | 2 -- both/lib/methods.js | 2 +- server/hooks.js | 4 ---- server/lib/methods.js | 24 ++++++++++++++++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 server/lib/methods.js diff --git a/both/lib/helpers.js b/both/lib/helpers.js index ce877fc..fb7ab00 100644 --- a/both/lib/helpers.js +++ b/both/lib/helpers.js @@ -37,5 +37,3 @@ daysUntilExpiration = function() { daysAgo.setDate(daysAgo.getDate() - daysToWait); return daysAgo; } - - diff --git a/both/lib/methods.js b/both/lib/methods.js index 0545a6e..c221f5a 100644 --- a/both/lib/methods.js +++ b/both/lib/methods.js @@ -36,13 +36,13 @@ Meteor.methods({ 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 diff --git a/server/hooks.js b/server/hooks.js index c608652..948050d 100644 --- a/server/hooks.js +++ b/server/hooks.js @@ -27,7 +27,3 @@ Jobs.after.insert(function(userId, doc) { text: "Job needs to be approved before it is live:\n\n" + Meteor.absoluteUrl("jobs/" + doc._id) + "\n\n\n\n\n\n" }); }); - -// Users.before.update(function(userId, doc) { -// -// }) 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) + }); + } + +}) From e4e5e3d15f5003ae8fd4dec82938e7adc55af455 Mon Sep 17 00:00:00 2001 From: chadnaylor Date: Fri, 3 Mar 2017 16:38:39 -0800 Subject: [PATCH 4/6] must be logged in and viewing active post for interested button to show --- both/lib/methods.js | 3 ++- client/views/jobs/job.html | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/both/lib/methods.js b/both/lib/methods.js index c221f5a..4c2d528 100644 --- a/both/lib/methods.js +++ b/both/lib/methods.js @@ -42,7 +42,8 @@ Meteor.methods({ if ( !userProfile ) throw new Meteor.Error("You must have a developer profile to register interest in a job."); - Meteor.call("sendJobInterestEmail", job) + + Meteor.call("sendJobInterestEmail", job); Users.update({ _id: this.userId diff --git a/client/views/jobs/job.html b/client/views/jobs/job.html index 6af63a2..13b631e 100644 --- a/client/views/jobs/job.html +++ b/client/views/jobs/job.html @@ -51,13 +51,17 @@


Featured Until {{formatDate featuredThrough}} {{/if}} -
- {{#if notInterested }} - I'm interested in this - {{else}} - The owner of this post has been notified of your interest. - {{/if}} -

+ {{#if currentUser }} + {{#if $eq status "active" }} +
+ {{#if notInterested }} + I'm interested in this + {{else}} + The owner of this post has been notified of your interest. + {{/if}} + {{/if}} + {{/if}} +
{{#if htmlDescription}} {{{htmlDescription}}} From 1047e44c16eb492ff5128acb4ae1bbf31ee296a9 Mon Sep 17 00:00:00 2001 From: chadnaylor Date: Fri, 3 Mar 2017 16:41:48 -0800 Subject: [PATCH 5/6] removed fields from publications --- both/lib/methods.js | 2 +- server/publications.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/both/lib/methods.js b/both/lib/methods.js index 4c2d528..921b747 100644 --- a/both/lib/methods.js +++ b/both/lib/methods.js @@ -48,7 +48,7 @@ Meteor.methods({ Users.update({ _id: this.userId }, { - $push: { + $addToSet: { interestedInJobIds: jobId } }); diff --git a/server/publications.js b/server/publications.js index 0ab185a..abd8a98 100644 --- a/server/publications.js +++ b/server/publications.js @@ -5,10 +5,6 @@ Meteor.publish(null, function () { return [ Users.find({ _id: this.userId - }, { - fields: { - interestedInJobIds: 1 - } }), Profiles.find({ userId: this.userId From 992e5e39178944cd399138c14572e9c50c2e088e Mon Sep 17 00:00:00 2001 From: chadnaylor Date: Fri, 3 Mar 2017 16:46:53 -0800 Subject: [PATCH 6/6] changed notInterested helper to interestedIn --- client/views/jobs/job.html | 6 +++--- client/views/jobs/job.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/views/jobs/job.html b/client/views/jobs/job.html index 13b631e..5df23f9 100644 --- a/client/views/jobs/job.html +++ b/client/views/jobs/job.html @@ -54,10 +54,10 @@

{{#if currentUser }} {{#if $eq status "active" }}
- {{#if notInterested }} - I'm interested in this - {{else}} + {{#if interestedIn }} The owner of this post has been notified of your interest. + {{else}} + I'm interested in this {{/if}} {{/if}} {{/if}} diff --git a/client/views/jobs/job.js b/client/views/jobs/job.js index 7d467ca..4530b00 100644 --- a/client/views/jobs/job.js +++ b/client/views/jobs/job.js @@ -18,11 +18,11 @@ Template.job.helpers({ return this.jobType || this.remote || this.featured; }, - 'notInterested': function () { + 'interestedIn': function () { if ( Meteor.user().interestedInJobIds ) { - return !Meteor.user().interestedInJobIds.includes(this._id) + return Meteor.user().interestedInJobIds.includes(this._id) } else { - return true; + return false; } } });