From e4547f3827266c1544a6919c884cb0ab01d7a4d7 Mon Sep 17 00:00:00 2001 From: Vuthy Date: Sun, 13 Jan 2019 16:39:10 +0700 Subject: [PATCH] Fix disapproving bug --- routes/apartment.js | 12 +++++++++--- routes/catering.js | 8 ++++---- routes/maintenance.js | 8 ++++---- routes/residence.js | 8 ++++---- routes/utilities.js | 8 ++++---- views/admin/admin_user_profile.handlebars | 1 + 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/routes/apartment.js b/routes/apartment.js index 68da2d3..f585c44 100644 --- a/routes/apartment.js +++ b/routes/apartment.js @@ -305,7 +305,7 @@ module.exports.set = function(router, pool) { await pool.query("UPDATE account SET budget = $1 WHERE email = $2;", [resultingRecipient, approveSystem.recipient]); await pool.query("UPDATE transfer_logs SET finished = 't',\ - approve_info = $1 WHERE id = $2;", [masterObj,fromUser.id]); + approve_info = $1, sender_resulting_budget = $2, recipient_resulting_budget = $3 WHERE id = $4;", [masterObj, resultingApartment, resultingRecipient, fromUser.id]); console.log("Transfered 3 responses!"); } @@ -315,10 +315,16 @@ module.exports.set = function(router, pool) { disapproved += 1; + + var resultingApartment = approveSystem.monApartment; + + var resultingRecipient = approveSystem.monRecipient; + + if(disapproved == 2 && encout == 0 && approveSystem.finished == false) { - await pool.query("UPDATE transfer_logs SET finished = 't',\ - approve_info = $1 WHERE id = $2;", [masterObj,fromUser.id]); + await pool.query("UPDATE transfer_logs SET finished = 't', canceled = 't',\ + approve_info = $1, sender_resulting_budget = $2, recipient_resulting_budget = $3 WHERE id = $4;", [masterObj, resultingApartment, resultingRecipient, fromUser.id]); console.log("Transfered fail, after 2 responses!"); } diff --git a/routes/catering.js b/routes/catering.js index e2f0322..09e3de2 100644 --- a/routes/catering.js +++ b/routes/catering.js @@ -29,7 +29,7 @@ module.exports.set = function(router, pool) { // This query should be faster than the next one // After next query is done, code will use row_number to calcuate the pagination system var paginateArray = [] - pool.query("SELECT count(id) from transfer_logs WHERE recipient = 'catering@ligercambodia.org' AND finished = 'true';", (err, result) => { + pool.query("SELECT count(id) from transfer_logs WHERE recipient = 'catering@ligercambodia.org' AND finished = 'true' AND canceled = 'false';", (err, result) => { var row_number = result.rows[0].count; console.log("Row number is " + row_number) // Generate array of object based on number of rows, limit and start @@ -63,7 +63,7 @@ module.exports.set = function(router, pool) { FROM transfer_logs \ JOIN account AS sender on (transfer_logs.sender = sender.email) \ JOIN account AS recipient on (transfer_logs.recipient = recipient.email) \ - WHERE transfer_logs.recipient = 'catering@ligercambodia.org' AND finished = 'true' \ + WHERE transfer_logs.recipient = 'catering@ligercambodia.org' AND finished = 'true AND canceled = 'false' \ ORDER BY date DESC, recipient_username DESC OFFSET $1 LIMIT $2;", values: [start, limit] } @@ -115,7 +115,7 @@ module.exports.set = function(router, pool) { var recentTransfer = { text: " SELECT transfer_logs.*, account.username as sender_username FROM transfer_logs \ JOIN account ON (transfer_logs.sender = account.email) \ - WHERE recipient = 'catering@ligercambodia.org' AND finished = 'true' \ + WHERE recipient = 'catering@ligercambodia.org' AND finished = 'true' AND canceled = 'false' \ ORDER BY date DESC LIMIT 4;" } @@ -133,7 +133,7 @@ module.exports.set = function(router, pool) { FROM transfer_logs \ JOIN (SELECT email, username, CASE WHEN role != 'apartment' THEN null ELSE username END AS apartment FROM account) AS account \ ON (transfer_logs.sender = account.email) \ - WHERE transfer_logs.recipient = 'catering@ligercambodia.org' AND transfer_logs.finished = 'true' \ + WHERE transfer_logs.recipient = 'catering@ligercambodia.org' AND transfer_logs.finished = 'true' AND transfer_logs.canceled = 'false' \ GROUP BY account.apartment ORDER BY account.apartment;" } diff --git a/routes/maintenance.js b/routes/maintenance.js index d7558c2..410723e 100644 --- a/routes/maintenance.js +++ b/routes/maintenance.js @@ -30,7 +30,7 @@ module.exports.set = function(router, pool) { // This query should be faster than the next one // After next query is done, code will use row_number to calcuate the pagination system var paginateArray = [] - pool.query("SELECT count(id) from transfer_logs WHERE recipient = 'maintenance@ligercambodia.org' AND finished = 'true';", (err, result) => { + pool.query("SELECT count(id) from transfer_logs WHERE recipient = 'maintenance@ligercambodia.org' AND finished = 'true' AND canceled = 'false';", (err, result) => { var row_number = result.rows[0].count; console.log("Row number is " + row_number) // Generate array of object based on number of rows, limit and start @@ -64,7 +64,7 @@ module.exports.set = function(router, pool) { FROM transfer_logs \ JOIN account AS sender on (transfer_logs.sender = sender.email) \ JOIN account AS recipient on (transfer_logs.recipient = recipient.email) \ - WHERE transfer_logs.recipient = 'maintenance@ligercambodia.org' AND finished = 'true' \ + WHERE transfer_logs.recipient = 'maintenance@ligercambodia.org' AND finished = 'true' AND canceled = 'false' \ ORDER BY date DESC, recipient_username DESC OFFSET $1 LIMIT $2;", values: [start, limit] } @@ -116,7 +116,7 @@ module.exports.set = function(router, pool) { var recentTransfer = { text: " SELECT transfer_logs.*, account.username as sender_username FROM transfer_logs \ JOIN account ON (transfer_logs.sender = account.email) \ - WHERE recipient = 'maintenance@ligercambodia.org' AND finished = 'true' \ + WHERE recipient = 'maintenance@ligercambodia.org' AND finished = 'true' AND canceled = 'false' \ ORDER BY date DESC LIMIT 4;" } @@ -134,7 +134,7 @@ module.exports.set = function(router, pool) { FROM transfer_logs \ JOIN (SELECT email, username, CASE WHEN role != 'apartment' THEN null ELSE username END AS apartment FROM account) AS account \ ON (transfer_logs.sender = account.email) \ - WHERE transfer_logs.recipient = 'maintenance@ligercambodia.org' AND transfer_logs.finished = 'true' \ + WHERE transfer_logs.recipient = 'maintenance@ligercambodia.org' AND transfer_logs.finished = 'true' AND transfer_logs.canceled = 'false' \ GROUP BY account.apartment ORDER BY account.apartment;" } diff --git a/routes/residence.js b/routes/residence.js index 44ecbc5..6e639f2 100644 --- a/routes/residence.js +++ b/routes/residence.js @@ -30,7 +30,7 @@ module.exports.set = function(router, pool) { // This query should be faster than the next one // After next query is done, code will use row_number to calcuate the pagination system var paginateArray = [] - pool.query("SELECT count(id) from transfer_logs WHERE recipient = 'residence@ligercambodia.org' AND finished = 'true';", (err, result) => { + pool.query("SELECT count(id) from transfer_logs WHERE recipient = 'residence@ligercambodia.org' AND finished = 'true' AND canceled = 'false';", (err, result) => { var row_number = result.rows[0].count; console.log("Row number is " + row_number) // Generate array of object based on number of rows, limit and start @@ -64,7 +64,7 @@ module.exports.set = function(router, pool) { FROM transfer_logs \ JOIN account AS sender on (transfer_logs.sender = sender.email) \ JOIN account AS recipient on (transfer_logs.recipient = recipient.email) \ - WHERE transfer_logs.recipient = 'residence@ligercambodia.org' AND finished = 'true' \ + WHERE transfer_logs.recipient = 'residence@ligercambodia.org' AND finished = 'true' AND canceled = 'false' \ ORDER BY date DESC, recipient_username DESC OFFSET $1 LIMIT $2;", values: [start, limit] } @@ -116,7 +116,7 @@ module.exports.set = function(router, pool) { var recentTransfer = { text: " SELECT transfer_logs.*, account.username as sender_username FROM transfer_logs \ JOIN account ON (transfer_logs.sender = account.email) \ - WHERE recipient = 'residence@ligercambodia.org' AND finished = 'true' \ + WHERE recipient = 'residence@ligercambodia.org' AND finished = 'true' AND canceled = 'false' \ ORDER BY date DESC LIMIT 4;" } @@ -134,7 +134,7 @@ module.exports.set = function(router, pool) { FROM transfer_logs \ JOIN (SELECT email, username, CASE WHEN role != 'apartment' THEN null ELSE username END AS apartment FROM account) AS account \ ON (transfer_logs.sender = account.email) \ - WHERE transfer_logs.recipient = 'residence@ligercambodia.org' AND transfer_logs.finished = 'true' \ + WHERE transfer_logs.recipient = 'residence@ligercambodia.org' AND transfer_logs.finished = 'true' AND transfer_logs.canceled = 'false' \ GROUP BY account.apartment ORDER BY account.apartment;" } diff --git a/routes/utilities.js b/routes/utilities.js index 3a3c1cf..2125c7f 100644 --- a/routes/utilities.js +++ b/routes/utilities.js @@ -24,7 +24,7 @@ module.exports.set = function(router, pool) { // This query should be faster than the next one // After next query is done, code will use row_number to calcuate the pagination system var paginateArray = [] - pool.query("SELECT count(id) from transfer_logs WHERE recipient = 'utilities@ligercambodia.org' AND finished = 'true';", (err, result) => { + pool.query("SELECT count(id) from transfer_logs WHERE recipient = 'utilities@ligercambodia.org' AND finished = 'true' AND canceled = 'false';", (err, result) => { var row_number = result.rows[0].count; console.log("Row number is " + row_number) // Generate array of object based on number of rows, limit and start @@ -58,7 +58,7 @@ module.exports.set = function(router, pool) { FROM transfer_logs \ JOIN account AS sender on (transfer_logs.sender = sender.email) \ JOIN account AS recipient on (transfer_logs.recipient = recipient.email) \ - WHERE transfer_logs.recipient = 'utilities@ligercambodia.org' AND finished = 'true' \ + WHERE transfer_logs.recipient = 'utilities@ligercambodia.org' AND finished = 'true' AND canceled = 'false' \ ORDER BY date DESC, recipient_username DESC OFFSET $1 LIMIT $2;", values: [start, limit] } @@ -110,7 +110,7 @@ module.exports.set = function(router, pool) { var recentTransfer = { text: " SELECT transfer_logs.*, account.username as sender_username FROM transfer_logs \ JOIN account ON (transfer_logs.sender = account.email) \ - WHERE recipient = 'utilities@ligercambodia.org' AND finished = 'true' \ + WHERE recipient = 'utilities@ligercambodia.org' AND finished = 'true' AND canceled = 'false' \ ORDER BY date DESC LIMIT 4;" } @@ -128,7 +128,7 @@ module.exports.set = function(router, pool) { FROM transfer_logs \ JOIN (SELECT email, username, CASE WHEN role != 'apartment' THEN null ELSE username END AS apartment FROM account) AS account \ ON (transfer_logs.sender = account.email) \ - WHERE transfer_logs.recipient = 'utilities@ligercambodia.org' AND transfer_logs.finished = 'true' \ + WHERE transfer_logs.recipient = 'utilities@ligercambodia.org' AND transfer_logs.finished = 'true' AND transfer_logs.canceled = 'false' \ GROUP BY account.apartment ORDER BY account.apartment;" } diff --git a/views/admin/admin_user_profile.handlebars b/views/admin/admin_user_profile.handlebars index 528d141..09d4552 100644 --- a/views/admin/admin_user_profile.handlebars +++ b/views/admin/admin_user_profile.handlebars @@ -239,6 +239,7 @@