Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // For refference, this is how my dataset returns from my mongoose request
- const emails = [{
- _id: 4632472,
- sender: 'zozimo@gmail.com',
- broadcasted: [{
- tracker_id: '111-222-333',
- email: 'claudio.fernando@gmail.com',
- file: '42348424284728421424/43216472462746242.pdf',
- name: 'claudio fernando maciel',
- sent: false,
- approved: 0,
- edited: false
- },
- {
- tracker_id: '222-333-444',
- email: 'jerry.lewis@gmail.com',
- file: '42348424284728421424/432164fdsafsadfas.pdf',
- name: 'jerry lewis',
- sent: false,
- approved: 1,
- edited: true
- }
- ]
- },
- {
- _id: 42384232,
- sender: 'klencher@gmail.com',
- broadcasted: [{
- tracker_id: '333-444-555',
- email: 'luiz@gmail.com',
- file: '42348424284728421424/45785hfsjdf.pdf',
- name: 'luiz diaz',
- sent: false,
- approved: 1,
- edited: true
- }]
- }
- ]
- // and here is the implementation as it used to look like (the new way is in the other gist
- // it's a little mixed with a few business rule. Yeah, it was pretty bad!
- preindicationJob: (dataset, template) => {
- var objEmails = [];
- var objEmail = {};
- objEmail.domain = config.worker.botdomain;
- //objEmail.data = { from: "Brokerme.Club <" + config.worker.bot + ">", to: config.worker.broker, subject: "Another Job Offer Campaign", html: "<p>hello world</p>" };
- if(dataset.values.length > 0) {
- var emails = dataset.values;
- var found = false;
- for(var j=0;j<emails.length;j++) {
- var campaign = emails[j].raw_data['title'];
- var email = emails[j];
- var tagCVs = "<tr>";
- for(var i=0;i<email.broadcasted.length;i++) {
- var cv = email.broadcasted[i];
- if(cv.approved == 0) {
- found = true;
- // tagCVs += "<td><a href='"+config.landingpage.address + config.landingpage.response+"response/approve/"+email._id+"/tracker_id/"+cv.tracker_id+"'";
- // tagCVs += " class='bt-marine bluey'>✓</a>";
- // tagCVs += "<td><a href='"+config.landingpage.address + config.landingpage.response+"response/reprove/"+email._id+"/tracker_id/"+cv.tracker_id+"'";
- // tagCVs += " class='bt-blood bloody'>x</a></td>";
- tagCVs += "<td> "+cv.name+" </td>";
- tagCVs += "<td><a href='"+cv.url+"'>"+cv.file+"</a></td>";
- if(i+1 != email.broadcasted.length) {
- tagCVs += "<tr> ";
- }
- else {
- tagCVs += "</tr>";
- }
- }
- }
- if(found) {
- var tagValues = {};
- tagValues.cvs = tagCVs;
- tagValues.subject = template.subject;
- tagValues.campaign = campaign;
- var parsedTemplate = dictionary.parseTemplate(template, tagValues, "approve-cvs");
- parsedTemplate = JSON.parse(JSON.stringify(parsedTemplate));
- var data = {
- from: "Brokerme.Club <" + config.worker.bot + ">",
- to: config.worker.broker,
- subject: parsedTemplate.subject,
- html: parsedTemplate.content
- };
- var items = email.broadcasted.filter(function(broad) { return (broad.approved == 0 )});
- objEmail.data = data;
- objEmail.email_id = email._id;
- objEmail.broadcasted = items.map(function(broad) { return broad.tracker_id; });
- objEmails.push(objEmail);
- }
- }
- }
- else {
- objEmail = {};
- }
- return objEmails;
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement