Skip to content

Commit

Permalink
Merge pull request #41 from chrisshayan/sprint5
Browse files Browse the repository at this point in the history
Sprint5
  • Loading branch information
tankhuu authored Sep 15, 2016
2 parents a408c8d + 742e3de commit dd306c2
Show file tree
Hide file tree
Showing 60 changed files with 1,921 additions and 1,541 deletions.
2 changes: 2 additions & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ vsivsi:job-collection
aldeed:moment-timezone
nimble:restivus
shell-server
lepozepo:accounting
okgrow:analytics
2 changes: 2 additions & 0 deletions .meteor/versions
3 changes: 3 additions & 0 deletions imports/api/cache/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Mongo} from 'meteor/mongo';

export const MiniMongo = new Mongo.Collection(null);
27 changes: 12 additions & 15 deletions imports/api/email/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const getRecipientInfo = ({recipient, sender}) => {
return false;
}
const recipientElements = recipient.split("-");
// console.log(recipientElements)
const
planId = recipientElements[0],
organizationId = recipientElements[1]
Expand Down Expand Up @@ -114,7 +113,6 @@ export const getSurveyEmailOptions = ({template, data}) => {
siteName: "",
leaderProfileUrl: "",
leaderName: "",
leaderGender: "",
alias: "",
orgName: "",
employeeName: "",
Expand Down Expand Up @@ -161,7 +159,6 @@ export const getSurveyEmailOptions = ({template, data}) => {
mailData.siteName = SITE_NAME;
mailData.leaderProfileUrl = `http://${mailData.alias}.${domain}`;
mailData.leaderName = `${capitalize(leader.firstName)} ${capitalize(leader.lastName)}`;
mailData.leaderGender = "";
mailData.orgName = `${capitalize(organization.name)}`;
mailData.employeeName = `${capitalize(employee.firstName)}`;
mailData.metric = capitalize(metric);
Expand All @@ -172,42 +169,42 @@ export const getSurveyEmailOptions = ({template, data}) => {
{
mailData.replyGuideHeader = EMAIL_TEMPLATE_CONTENT.metrics.replyGuideHeader;
mailData.replyGuideMessage = EMAIL_TEMPLATE_CONTENT.metrics.replyGuideMessage;
mailData.message = `Please help your leader "${mailData.leaderName}" to improve "${mailData.metric}" management by giving ${mailData.leaderGender} a score.`;
mailData.message = `Please help your leader "${mailData.leaderName}" to improve "${mailData.metric}" management by giving a score.`;
mailData.description = EMAIL_TEMPLATE_CONTENT.metrics[metric];
senderSuffix = template;
subject = `${mailData.employeeName}, How "${mailData.leaderName}" can improve ${mailData.leaderGender} score on ${mailData.metric} Management?`;
subject = `${mailData.employeeName}, How "${mailData.leaderName}" can improve ${mailData.metric} Management?`;

break;
}
case "survey_error":
{
mailData.replyGuideHeader = EMAIL_TEMPLATE_CONTENT.metrics.replyGuideHeader;
mailData.replyGuideMessage = EMAIL_TEMPLATE_CONTENT.metrics.replyGuideMessage;
mailData.message = `Please help your leader "${mailData.leaderName}" to improve "${mailData.metric}" management by giving ${mailData.leaderGender} a score.`;
mailData.message = `Please help "${mailData.leaderName}" to improve "${mailData.metric}" management by giving accurate score. The score should be a number from 1 to 5. If you think ${mailData.leaderName} is doing a great job, just reply the email by sending 5. If you think ${mailData.leaderName} is doing moderate job reply the email by sending 3 and if ${mailData.leaderName} is doing very bad then send 1.`;
mailData.description = EMAIL_TEMPLATE_CONTENT.metrics[metric];
senderSuffix = "survey";
subject = `Please correct the score about "${mailData.metric}" for ${mailData.leaderName} in ${mailData.orgName}.`;
subject = `${mailData.employeeName}, seems the score of "${mailData.metric}" has some issues.`;

break;
}
case "feedback":
{
mailData.replyGuideHeader = EMAIL_TEMPLATE_CONTENT[template].replyGuideHeader;
mailData.replyGuideMessage = `Simply reply this email with your suggestion for ${mailData.leaderName} to improve ${mailData.leaderGender} ${mailData.metric} Management.`;
mailData.message = `Help your leader "${mailData.leaderName}" to improve "${mailData.metric}" Management.`;
mailData.description = EMAIL_TEMPLATE_CONTENT[template].description;
mailData.replyGuideMessage = `Simply reply this email with your suggestion and write whatever you think is good.`;
mailData.message = `"${mailData.leaderName}" needs your help to improve "${mailData.metric}" Management.`;
mailData.description = `Your feedback is very important and it will be kept CONFIDENTIAL, it means ${mailData.leaderName} won’t be able to know who submitted the feedback.`;
senderSuffix = template;
subject = `How could "${mailData.leaderName}" improve the ${mailData.metric} for higher score?`;
subject = `${mailData.employeeName}, "${mailData.leaderName}" wants to improve ${mailData.metric}, how?`;
break;
}
case "thankyou":
{
const {type} = data;
mailData.message = `Thank you very much for your ${type} to "${mailData.leaderName}" about ${mailData.leaderGender} "${mailData.metric}" Management.`;
mailData.description = `Your ${type} will help the leader to improve ${mailData.leaderGender} ability.`;
mailData.viewLeaderProfileHeader = `Want to view ${mailData.leaderName} profile?`;
mailData.message = `I appreciate your contribution on "${mailData.metric}" Management. I believe better leadership can help all of us to enjoy our daily life even more. Besides, it is very effective for you as an individual. The better the leader, happier employee.\nBest Regards,\ntheLeader.io on behalf of "${mailData.leaderName}"`;
mailData.description = `Your ${type} will help ${mailData.leaderName} to improve.`;
mailData.viewLeaderProfileHeader = `View ${mailData.leaderName} public profile?`;
senderSuffix = template;
subject = `Thank you for your ${type}`;
subject = `${mailData.employeeName}, You’ve been heard. Leadership matters.`;
break;
}
}
Expand Down
1 change: 0 additions & 1 deletion imports/api/email/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export const send = new ValidatedMethod({
case 'survey':
{
const options = EmailFunctions.getSurveyEmailOptions({template, data});
console.log(options)
Email.send(options);
break;
}
Expand Down
2 changes: 2 additions & 0 deletions imports/api/employees/register.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './methods';
import './server/publications';
13 changes: 13 additions & 0 deletions imports/api/employees/server/publications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Meteor} from 'meteor/meteor';
import {Employees} from '../index';

Meteor.publish('employees', function() {
if(!this.userId) {
return this.ready();
}

return Employees.find({leaderId: this.userId}, {
fields: Employees.publicFields
});

});
3 changes: 2 additions & 1 deletion imports/api/feedbacks/register.server.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './methods';
import './methods';
import './server/publications';
7 changes: 7 additions & 0 deletions imports/api/jobs/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ function createJob(type, attributes, data) {
job = new Job(DailyJobs, type, data);
break;
}
case "measure_metric": {
job = new Job(DailyJobs, type, data);
break;
}
case "send_surveys": {
job = new Job(QueueJobs, type, data);
break;
}
default: {
return `Unknown job type: ${type}`
}
}
const currentDate = new Date();
const {
Expand Down
47 changes: 37 additions & 10 deletions imports/api/jobs/workers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Mongo} from 'meteor/mongo';
import {DailyJobs, QueueJobs} from './collections';
import {words as capitalize} from 'capitalize';
import moment from 'moment';
import _ from 'lodash';

// collections
import {Organizations} from '/imports/api/organizations/index';
Expand All @@ -11,8 +13,7 @@ import * as EmailActions from '/imports/api/email/methods';
import {getSendingPlans} from '/imports/api/sending_plans/methods';
import {getLocalDate} from '/imports/api/time/functions';
import {setStatus as setSendingPlanStatus} from '/imports/api/sending_plans/methods';


import {measureMonthlyMetricScore} from '/imports/api/measures/methods';

// constants
const LOG_LEVEL = {
Expand Down Expand Up @@ -75,10 +76,11 @@ const enqueueSurveys = function (job, cb) {
};
const attributes = {
priority: "normal",
after: new Date(getLocalDate(date, timezone))
after: new Date(getLocalDate(sendDate, timezone))
};
enqueue.call({type: "send_surveys", attributes, data: queueData}, (error) => {
if (_.isEmpty(error)) {
setSendingPlanStatus.call({_id: planId, status: "QUEUED"});
jobMessage = `Enqueue mail ${metric} to ${employee.email} on ${date}`;
job.log(jobMessage, {level: LOG_LEVEL.INFO});
} else {
Expand Down Expand Up @@ -116,7 +118,6 @@ const sendSurveys = function (job, cb) {
job.log(jobMessage, {level: LOG_LEVEL.WARNING});
job.done();
} else {
// console.log({employeeId, leaderId, organizationId, metric});
const template = 'survey';
const data = {
planId,
Expand All @@ -126,12 +127,11 @@ const sendSurveys = function (job, cb) {
metric
};
EmailActions.send.call({template, data}, (error) => {
if(_.isEmpty(error)) {
if (_.isEmpty(error)) {
setSendingPlanStatus.call({_id: planId, status: "SENT"});
job.done();
} else {
setSendingPlanStatus.call({_id: planId, status: "FAILED"});
console.log(error);
jobMessage = error.reason;
job.log(jobMessage, {level: LOG_LEVEL.WARNING});
job.done();
Expand All @@ -145,13 +145,40 @@ const sendSurveys = function (job, cb) {

}

const measureMetrics = (job, cb) => {
measureMonthlyMetricScore.call({params: {}}, (error, measure) => {
if (!error) {
if (!_.isEmpty(measure)) {
jobMessage = `measured metrics for ${measure.noOfLeader} leaders and ${measure.noOfOrg} organizations done`;
job.log(jobMessage, {level: LOG_LEVEL.INFO});
job.done();
} else {
jobMessage = `No data to measure for job: ${job}`;
job.log(jobMessage, {level: LOG_LEVEL.WARNING});
job.done();
}
} else {
job.log(error.reason, {level: LOG_LEVEL.CRITICAL});
job.fail();
}
});
}

// Start Job
function startJob(type) {
switch(type) {
case "enqueue_surveys": {
switch (type) {
// daily jobs
case "enqueue_surveys":
{
DailyJobs.processJobs(type, enqueueSurveys);
}
case "send_surveys": {
case "measure_metric":
{
DailyJobs.processJobs(type, measureMetrics);
}
// queue jobs
case "send_surveys":
{
QueueJobs.processJobs(type, sendSurveys);
}
}
Expand Down
5 changes: 5 additions & 0 deletions imports/api/measures/collections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Mongo} from 'meteor/mongo';

export default class MeasuresCollection extends Mongo.Collection {

}
Loading

0 comments on commit dd306c2

Please sign in to comment.