mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-28 15:03:57 -04:00
Filter out low priority sales leads on initial import
This commit is contained in:
parent
672c89e0bc
commit
b8dd0f0a45
1 changed files with 28 additions and 7 deletions
|
@ -90,13 +90,14 @@ function upsertLeads(done) {
|
||||||
|
|
||||||
// ** Utilities
|
// ** Utilities
|
||||||
|
|
||||||
function getInitialLeadStatusViaCountry(country) {
|
function getInitialLeadStatusViaCountry(country, trialRequests) {
|
||||||
if (/usa|america|united states/ig.test(country)) {
|
if (/usa|america|united states/ig.test(country)) {
|
||||||
return 'New US Schools Auto Attempt 1';
|
const status = 'New US Schools Auto Attempt 1'
|
||||||
|
return isLowValueLead(status, trialRequests) ? `${status} Low` : status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInitialLeadStatusViaEmails(emails) {
|
function getInitialLeadStatusViaEmails(emails, trialRequests) {
|
||||||
let currentStatus = null;
|
let currentStatus = null;
|
||||||
let currentRank = closeIoInitialLeadStatuses.length;
|
let currentRank = closeIoInitialLeadStatuses.length;
|
||||||
for (const email of emails) {
|
for (const email of emails) {
|
||||||
|
@ -109,7 +110,25 @@ function getInitialLeadStatusViaEmails(emails) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return currentStatus ? currentStatus : closeIoInitialLeadStatuses[closeIoInitialLeadStatuses.length - 1].status;
|
currentStatus = currentStatus ? currentStatus : closeIoInitialLeadStatuses[closeIoInitialLeadStatuses.length - 1].status;
|
||||||
|
return isLowValueLead(currentStatus, trialRequests) ? `${currentStatus} Low` : currentStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isLowValueLead(status, trialRequests) {
|
||||||
|
if (['Auto Attempt 1', 'New US Schools Auto Attempt 1'].indexOf(status) >= 0) {
|
||||||
|
for (const trialRequest of trialRequests) {
|
||||||
|
if (parseInt(trialRequest.properties.nces_district_students) < 5000) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const trialRequest of trialRequests) {
|
||||||
|
// Must match these values: https://github.com/codecombat/codecombat/blob/master/app/templates/teachers/request-quote-view.jade#L159
|
||||||
|
if (['1-500', '500-1,000'].indexOf(trialRequest.properties.numStudentsTotal) >= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomEmailApiKey() {
|
function getRandomEmailApiKey() {
|
||||||
|
@ -246,6 +265,7 @@ class CocoLead {
|
||||||
this.contacts = {};
|
this.contacts = {};
|
||||||
this.custom = {};
|
this.custom = {};
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.trialRequests = [];
|
||||||
}
|
}
|
||||||
addClassroom(email, classroom) {
|
addClassroom(email, classroom) {
|
||||||
if (!this.contacts[email.toLowerCase()]) this.contacts[email.toLowerCase()] = {};
|
if (!this.contacts[email.toLowerCase()]) this.contacts[email.toLowerCase()] = {};
|
||||||
|
@ -270,6 +290,7 @@ class CocoLead {
|
||||||
this.contacts[email.toLowerCase()].name = trial.properties.name;
|
this.contacts[email.toLowerCase()].name = trial.properties.name;
|
||||||
}
|
}
|
||||||
this.contacts[email.toLowerCase()].trial = trial;
|
this.contacts[email.toLowerCase()].trial = trial;
|
||||||
|
this.trialRequests.push(trial);
|
||||||
}
|
}
|
||||||
addUser(email, user) {
|
addUser(email, user) {
|
||||||
this.contacts[email.toLowerCase()].user = user;
|
this.contacts[email.toLowerCase()].user = user;
|
||||||
|
@ -278,11 +299,11 @@ class CocoLead {
|
||||||
for (const email in this.contacts) {
|
for (const email in this.contacts) {
|
||||||
const props = this.contacts[email].trial.properties;
|
const props = this.contacts[email].trial.properties;
|
||||||
if (props && props['country']) {
|
if (props && props['country']) {
|
||||||
const status = getInitialLeadStatusViaCountry(props['country']);
|
const status = getInitialLeadStatusViaCountry(props['country'], this.trialRequests);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getInitialLeadStatusViaEmails(Object.keys(this.contacts));
|
return getInitialLeadStatusViaEmails(Object.keys(this.contacts), this.trialRequests);
|
||||||
}
|
}
|
||||||
getLeadPostData() {
|
getLeadPostData() {
|
||||||
const postData = {
|
const postData = {
|
||||||
|
@ -502,8 +523,8 @@ function updateExistingLead(lead, existingLead, done) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveNewLead(lead, done) {
|
function saveNewLead(lead, done) {
|
||||||
// console.log('DEBUG: saveNewLead', lead.name);
|
|
||||||
const postData = lead.getLeadPostData();
|
const postData = lead.getLeadPostData();
|
||||||
|
// console.log(`DEBUG: saveNewLead ${lead.name} ${postData.status}`);
|
||||||
const options = {
|
const options = {
|
||||||
uri: `https://${closeIoApiKey}:X@app.close.io/api/v1/lead/`,
|
uri: `https://${closeIoApiKey}:X@app.close.io/api/v1/lead/`,
|
||||||
body: JSON.stringify(postData)
|
body: JSON.stringify(postData)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue