Skip to content
This repository was archived by the owner on Jun 21, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 77 additions & 57 deletions Message.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { workers } from 'cluster';

'use strict';

const sqlite3 = require('sqlite3').verbose();
Expand Down Expand Up @@ -105,7 +107,7 @@ let csvMessageObjs = [
},
]
//Methods for the EMAIL data
//this will not need to be in the production version as the DB will already exist! Just for my build purposes -EL
// //this will not need to be in the production version as the DB will already exist! Just for my build purposes -EL

// db.serialize( () => {

Expand Down Expand Up @@ -135,13 +137,9 @@ let csvMessageObjs = [
// relatedStudentContactId TEXT,
// softBounce TEXT NOT NULL,
// subjectLine TEXT


// )`);




// module.exports.prepEmailData = (data) => {
// console.log('printData firing', data["Contact Record Type"]);
// data.forEach(d => {
Expand Down Expand Up @@ -172,31 +170,31 @@ let csvMessageObjs = [
// };

// //POST from upload, iterate over each of the items in the parsed array of objects:
// module.exports.insertEmailsIntoDB = (csvEmailObjs) => {
// csvEmailObjs.forEach( (emailObj) => {
// db.run(`INSERT INTO EmailFiles VALUES (null,
// '${emailObj.clicked}',
// '${emailObj.contact}',
// '${emailObj.contactId}',
// '${emailObj.contactRecordType}',
// '${emailObj.dateBounced}',
// '${emailObj.dateOpened}',
// '${emailObj.dateSent}',
// '${emailObj.dateUnsubscribed}',
// '${emailObj.deleted}',
// '${emailObj.email}',
// '${emailObj.emailName}',
// '${emailObj.fromAddress}',
// '${emailObj.fromName}',
// '${emailObj.hardBounce}',
// ${emailObj.numberOfTotalClicks},
// ${emailObj.numberOfUniqueClicks},
// '${emailObj.opened}',
// '${emailObj.relatedStudentContactId}',
// '${emailObj.softBounce}',
// '${emailObj.subjectLine}')`);
// });
// }
module.exports.insertEmailsIntoDB = (csvEmailObjs) => {
csvEmailObjs.forEach( (emailObj) => {
db.run(`INSERT INTO EmailFiles VALUES (null,
'${emailObj.clicked}',
'${emailObj.contact}',
'${emailObj.contactId}',
'${emailObj.contactRecordType}',
'${emailObj.dateBounced}',
'${emailObj.dateOpened}',
'${emailObj.dateSent}',
'${emailObj.dateUnsubscribed}',
'${emailObj.deleted}',
'${emailObj.email}',
'${emailObj.emailName}',
'${emailObj.fromAddress}',
'${emailObj.fromName}',
'${emailObj.hardBounce}',
${emailObj.numberOfTotalClicks},
${emailObj.numberOfUniqueClicks},
'${emailObj.opened}',
'${emailObj.relatedStudentContactId}',
'${emailObj.softBounce}',
'${emailObj.subjectLine}')`);
});
}



Expand Down Expand Up @@ -281,9 +279,9 @@ module.exports.insertMessagesIntoDB = (csvMessageObjs) => {



//uncommenting this will call this function and input those objects above
// module.exports.insertEmailsIntoDB(csvEmailObjs);
// module.exports.insertMessagesIntoDB(csvMessageObjs);
// // //uncommenting this will call this function and input those objects above
// module.exports.insertEmailsIntoDB(csvEmailObjs);
// // // module.exports.insertMessagesIntoDB(csvMessageObjs);
// });

module.exports.searchByContactId = (contactId) => {
Expand All @@ -295,35 +293,57 @@ module.exports.searchByContactId = (contactId) => {
});
};


module.exports.uploadFileToDB = (file) => {
console.log("file going in", file);
//clean up and start building out step by step
module.exports.uploadFileToDB = (fileObjsArr) => {
console.log("file going in");
console.log("fileObjsArr, fakely 0", fileObjsArr[0]['Contact ID']);
return new Promise( (resolve, reject) => {
db.all(`INSERT INTO EmailFiles VALUES (null,
'${file.contactId}',
'${file.clicked}',
'${file.contact}',
'${file.contactRecordType}',
'${file.dateBounced}',
'${file.dateOpened}',
'${file.dateSent}',
'${file.dateUnsubscribed}',
'${file.deleted}',
'${file.email}',
'${file.emailName}',
'${file.fromAddress}',
'${file.fromName}',
'${file.hardBounce}',
${file.numberOfTotalClicks},
${file.numberOfUniqueClicks},
'${file.opened}',
'${file.relatedStudentContactId}',
'${file.softBounce}',
'${file.subjectLine}')`,
console.log("fileObjsArr, fakely 1", fileObjsArr[0]['Contact ID']);

//create empty strings/sub numbers for all values just in case

//try checking out a new branch and then using the same front end stuff??

//try making a whole new back end based on what you have learned with sequelize
// then see if you can use something like bulkinsert... find out how papaparse works and
//if that can be a json file... maybe stdout write it to a file or something
//then you should be able to use that as a 'seeder' ... but is there a way to sequelize it
//straight as a json collection, like instead of importing from a seed data file let {} = require whatever
//just go ahead and straight up import and then bulkinsert that stuff?

fileObjsArr.forEach( (file) => {
if (file['Contact ID']) {

console.log("file file file", file);
db.run(`INSERT INTO EmailFiles (contactId, clicked) VALUES ("${file['Contact ID']}", "${file.Clicked}")`,
// '${file.Clicked}',
// '${file.Contact}',
// '${file['Contact ID']}',
// '${file["Contact Record Type"]}',
// '${file["Date Bounced"]}',
// '${file['Date Opened']}',
// '${file["Date Sent"]}',
// '${file["Date Unsubscribed"]}',
// '${file.Deleted}',
// '${file.Email}',
// '${file["Email Name"]}',
// '${file['From Address']}',
// '${file["From Name"]}',
// '${file["Hard Bounce"]}',
// ${file["Number Of Total Clicks"]},
// ${file["Number Of Unique Clicks"]},
// '${file.Opened}',
// '${file["Related Student Contact ID"]}',
// '${file["Soft Bounce"]}',
// '${file["Subject Line"]}'
// ),
(err, successMessage) => {
if (err) return reject(err);//if error, pass on to error handler
resolve(successMessage);
});
//ask JUFE - or someone - how can I resolve this not inside foreach?- or what else to do here
}
})
});
};

Expand Down
25 changes: 23 additions & 2 deletions app/factories/upload-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ app.factory('uploadFactory', function ($q, $http) {
});
};

//send to API -- OPTION ONE

function uploadToApi(arrObj){
console.log("arrObj", arrObj);
return $q((resolve, reject)=>{
$http.post(`http://localhost:3000/uploadfile/${arrObj}`)
$http({
method: 'POST',
url: 'http://localhost:3000/uploadfile',
// data: {"fake_json": "This is a small string."},
data: arrObj,
headers: {'Content-Type': 'application/json'}
})
.then((data) => {
console.log("uploaded to Api?", data);
resolve();
Expand All @@ -28,6 +35,20 @@ app.factory('uploadFactory', function ($q, $http) {
});
});
}
// //send to API -- OPTION ONE
// function uploadToApi(arrObj){
// return $q((resolve, reject)=>{
// $http.post(`http://localhost:3000/uploadfile/${arrObj}`)
// .then((data) => {
// console.log("uploaded to Api?", data);
// resolve();
// })
// .catch( (err) => {
// reject(err);
// });
// });
// }


// //send to API -- OPTION TWO
// function uploadToApi(arrObj){
Expand Down
1 change: 1 addition & 0 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"angular": "^1.6.6",
"angular-route": "^1.6.6",
"angular-ui-bootstrap": "^2.5.0",
"body-parser": "^1.18.2",
"bootstrap": "^4.0.0-beta",
"express": "^4.16.1",
"grunt": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion messageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let getMessagesByContactId = (req, res, next) => {
};

let uploadFileFromWeb = (req, res, next) => {
uploadFileToDB(req.params.file)
uploadFileToDB(req.body)
.then( (results) => {
//do something with results-- send to front end for usable form, they will just be JSON so far
res.status(200).json(results);
Expand Down
14 changes: 10 additions & 4 deletions nodeApp.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'use strict';

let express = require('express');
let app = express();
let routes = require('./routes.js');
const express = require('express');
const app = express();
const routes = require('./routes.js');
const bodyParser = require('body-parser');
const cors = require('cors');


app.use(bodyParser.json());
app.use(cors());

app.use('/', routes);

Expand All @@ -17,7 +23,7 @@ app.use( (err, req, res, next) => {
res.status(err.status||500);
res.json({
message:"A problem occurred.",
err:err
err: err
})
});

Expand Down
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "tnAchieves-Communication-Archive",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"concat": "^1.0.3",
"connect": "^3.6.5",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"jshint": "^2.9.5",
"jshint-stylish": "^2.2.1",
"matchdep": "^2.0.0",
"nodemon": "^1.12.1",
"sass": "^1.0.0-beta.2",
"sqlite3": "^3.1.13",
"watch": "^1.0.2"
},
"dependencies": {
"angular": "^1.6.6",
"angular-route": "^1.6.6",
"angular-ui-bootstrap": "^2.5.0",
"body-parser": "^1.18.2",
"bootstrap": "^4.0.0-beta",
"cors": "^2.8.4",
"express": "^4.16.1",
"grunt": "^1.0.1",
"jquery": "^3.2.1",
"popper.js": "^1.12.5"
},
"description": ""
}
2 changes: 1 addition & 1 deletion routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { sayHello } = require('./helloCtrl.js');

router.get('/messages/:id', getMessagesByContactId); //if this route, get all emails attached to a certain id

router.post('/uploadfile/:file', uploadFileFromWeb); //if this route, get all emails attached to a certain id
router.post('/uploadfile', uploadFileFromWeb); //if this route, get all emails attached to a certain id
// router.post('/email/upload', postEmailData);
router.get('/hello', sayHello);

Expand Down
Binary file removed tnAchieves.sqlite
Binary file not shown.