-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from VuthyVey/development
Development
- Loading branch information
Showing
10 changed files
with
101 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
// var credentials = { | ||
// user:'[email protected]', | ||
// pass:'zxivzkliyluhagcq' | ||
// }; | ||
|
||
var credentials = { | ||
user:'[email protected]', | ||
pass:'zxivzkliyluhagcq' | ||
user:'[email protected]', | ||
pass:'yoywnomlwolmysjk' | ||
}; | ||
|
||
var sEmail = false; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,12 @@ module.exports.set = function(router, pool) { | |
var apartmentTransferBudget = 0; | ||
var emailsList = []; | ||
|
||
for(var i = 0; i < emails.rows.length; i++){ | ||
emailsList.push(emails.rows[i].email); | ||
var emailToRemove = await pool.query("SELECT email FROM account WHERE role = 'senior_student' or role = 'apartment' or email = '[email protected]' or role = 'central_bank' ORDER BY role, username"); | ||
|
||
for(var i = 0; i < emailToRemove.rows.length; i++){ | ||
emailsList.push(emailToRemove.rows[i].email); | ||
} | ||
console.log(emailsList); | ||
if(apartmentTransfer.rows){ | ||
for(var i = 0; i < apartmentTransfer.rows.length; i++){ | ||
apartmentTransferBudget += parseFloat(apartmentTransfer.rows[i].amount); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,42 +75,69 @@ module.exports.set = function(router, pool) { | |
// console.log("came in here \n\n\n\n"); | ||
console.log('"'+exchangeLog.reason+'"'); | ||
|
||
// //get total amount for that day | ||
// var totalExchange = await pool.query("SELECT amount FROM exchange_list WHERE email = $1 and apptDate = $2", [exchangeLog.email, apptDate]); | ||
// //sum it all up | ||
// var exchangeSum; | ||
|
||
// for (var i = 0 ; i < totalExchange.rows.length; i++){ | ||
// exchangeSum += parseFloat(totalExchange.rows[i].amount); | ||
// console.log("for i "+i+" amount "+parseFloat(totalExchange.rows[i].amount); | ||
// } | ||
// console.log("total: "+exchangeSum); | ||
var notValid = exchangeLog.amount > 20 && exchangeLog.reason == ""; | ||
var over20 = exchangeLog.amount > 20; | ||
//get total amount for that day | ||
var totalExchange = await pool.query("SELECT * FROM exchange_list WHERE email = $1 and apptDate = $2", [exchangeLog.email, apptDate]); | ||
//sum it all up | ||
var exchangeSum = 0; | ||
|
||
for (var i = 0 ; i < totalExchange.rows.length; i++){ | ||
exchangeSum += parseFloat(totalExchange.rows[i].amount); | ||
console.log("for i "+i+" amount "+parseFloat(totalExchange.rows[i].amount)); | ||
} | ||
exchangeSum += parseFloat(exchangeLog.amount); | ||
console.log("total: "+exchangeSum); | ||
var notValid = exchangeSum > 20 && exchangeLog.reason == ""; | ||
var over20 = exchangeSum > 20; | ||
if (notValid){ | ||
res.send("Reason Required!"); | ||
console.log("Reason Required!"); | ||
return; | ||
} | ||
|
||
|
||
pool.query(getApartment, function(apartmentErr, apartmentResult){ | ||
pool.query(getApartment, async function(apartmentErr, apartmentResult){ | ||
if(apartmentErr){console.log(apartmentErr);} | ||
else{ | ||
var apartment = apartmentResult.rows[0].apartment; | ||
|
||
|
||
|
||
|
||
//get existing apptdate | ||
var existingApptDate = await pool.query("SELECT * FROM exchange_list WHERE email = $1 and apptDate = $2", [exchangeLog.email, apptDate]); | ||
|
||
console.log("existingApptDate = "+existingApptDate); | ||
if (existingApptDate.rows[0] == null){ | ||
var apptDateExist = false; | ||
}else{ | ||
var apptDateExist = true; | ||
} | ||
|
||
if (apptDateExist){ | ||
pool.query("DELETE FROM exchange_list WHERE id = $1;", [totalExchange.rows[0].id], async function(errDel, resultDel) { | ||
console.log("Deleting ID: "+ totalExchange.rows[0].id); | ||
if(err){ | ||
res.send(errDel); | ||
} | ||
}); | ||
console.log("Appointment Date Exist"); | ||
}else{ | ||
console.log("Appointment Date Doesn't Exist"); | ||
} | ||
|
||
// console.log("apptDateExist = "+apptDateExist+"\ninsertData = "+ insertData); | ||
const insertData = { | ||
text: "INSERT INTO exchange_list (timeCreated, person, email, type, amount, result, reason, apptdate, apartment)\ | ||
VALUES (CURRENT_TIMESTAMP(2), $1, $2, $3, $4::float8::numeric::money, $5::float8::numeric::money, $6, $7, $8) returning id as id;", | ||
values: [exchangeLog.person, exchangeLog.email, exchangeLog.type, exchangeLog.amount, exchangeLog.result, exchangeLog.reason, apptDate, apartment] | ||
text: "INSERT INTO exchange_list (timeCreated, person, email, type, amount, result, reason, apptdate, apartment)\ | ||
VALUES (CURRENT_TIMESTAMP(2), $1, $2, $3, $4::float8::numeric::money, $5::float8::numeric::money, $6, $7, $8) returning id as id;", | ||
values: [exchangeLog.person, exchangeLog.email, exchangeLog.type, exchangeSum, exchangeSum, exchangeLog.reason, apptDate, apartment] | ||
}; | ||
|
||
|
||
pool.query(insertData, async function(insertErr, insertResult) { | ||
if (insertErr) { | ||
if (insertErr) { | ||
console.log(insertErr); | ||
} else { | ||
console.log("inserted data with id = "+ insertResult.rows[0].id); | ||
|
||
if (exchangeLog.type == "pedro-dollar"){ | ||
if (!over20){ | ||
|
@@ -122,6 +149,8 @@ module.exports.set = function(router, pool) { | |
}); | ||
} | ||
|
||
|
||
|
||
/* | ||
send email to all re | ||
"Subject: Exchange Request | ||
|
@@ -136,7 +165,7 @@ module.exports.set = function(router, pool) { | |
*/ | ||
|
||
//get email recipient / all re emails | ||
var emailRecipientData = await pool.query("SELECT email FROM account WHERE role = $1",["re"]); | ||
var emailRecipientData = await pool.query("SELECT email FROM account WHERE role = $1",['re']); | ||
|
||
//get requester's email | ||
//exchangeLog.email; | ||
|
@@ -186,7 +215,7 @@ module.exports.set = function(router, pool) { | |
//send to requester | ||
email.sendEmail(exchangeLog.email, "Exchange Request Sent", contentToRequester); | ||
// email.sendEmail("[email protected]", "Exchange Request Sent", contentToRequester+"<br>Target: "+exchangeLog.email); | ||
}else{ | ||
}else{//if type isn't pedro to dollar | ||
//get requester's email | ||
//exchangeLog.email; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,19 @@ module.exports.set = function(router, pool) { | |
pool.query(getAccount, function(accErr, accresult) { | ||
if(accErr){console.log(accErr);} | ||
else{ | ||
pool.query(getAccountAll, function(allAccErr, allAccResult) { | ||
pool.query(getAccountAll, async function(allAccErr, allAccResult) { | ||
if(allAccErr){console.log(allAccErr);} | ||
else{ | ||
var emailsList = []; | ||
for(var i = 0; i < allAccResult.rows.length; i++){ | ||
emailsList.push(allAccResult.rows[i].email); | ||
|
||
|
||
var emailToRemove = await pool.query("SELECT email FROM account WHERE role = 'senior_student' or role = 'apartment' or email = '[email protected]' or role = 'central_bank' ORDER BY role, username"); | ||
|
||
for(var i = 0; i < emailToRemove.rows.length; i++){ | ||
emailsList.push(emailToRemove.rows[i].email); | ||
} | ||
console.log(emailsList); | ||
|
||
console.log("About to query!"); | ||
pool.query(getExchange, function(exchangeErr, exchangeResult) { | ||
if(exchangeErr){console.log(exchangeErr);} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters