Skip to content

Commit

Permalink
Fix disapproving bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Vuthy committed Jan 13, 2019
1 parent 67b6a2c commit e4547f3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
12 changes: 9 additions & 3 deletions routes/apartment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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!");
}
Expand Down
8 changes: 4 additions & 4 deletions routes/catering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]' AND finished = 'true';", (err, result) => {
pool.query("SELECT count(id) from transfer_logs WHERE recipient = '[email protected]' 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
Expand Down Expand Up @@ -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 = '[email protected]' AND finished = 'true' \
WHERE transfer_logs.recipient = '[email protected]' AND finished = 'true AND canceled = 'false' \
ORDER BY date DESC, recipient_username DESC OFFSET $1 LIMIT $2;",
values: [start, limit]
}
Expand Down Expand Up @@ -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 = '[email protected]' AND finished = 'true' \
WHERE recipient = '[email protected]' AND finished = 'true' AND canceled = 'false' \
ORDER BY date DESC LIMIT 4;"
}

Expand All @@ -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 = '[email protected]' AND transfer_logs.finished = 'true' \
WHERE transfer_logs.recipient = '[email protected]' AND transfer_logs.finished = 'true' AND transfer_logs.canceled = 'false' \
GROUP BY account.apartment ORDER BY account.apartment;"
}

Expand Down
8 changes: 4 additions & 4 deletions routes/maintenance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]' AND finished = 'true';", (err, result) => {
pool.query("SELECT count(id) from transfer_logs WHERE recipient = '[email protected]' 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
Expand Down Expand Up @@ -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 = '[email protected]' AND finished = 'true' \
WHERE transfer_logs.recipient = '[email protected]' AND finished = 'true' AND canceled = 'false' \
ORDER BY date DESC, recipient_username DESC OFFSET $1 LIMIT $2;",
values: [start, limit]
}
Expand Down Expand Up @@ -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 = '[email protected]' AND finished = 'true' \
WHERE recipient = '[email protected]' AND finished = 'true' AND canceled = 'false' \
ORDER BY date DESC LIMIT 4;"
}

Expand All @@ -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 = '[email protected]' AND transfer_logs.finished = 'true' \
WHERE transfer_logs.recipient = '[email protected]' AND transfer_logs.finished = 'true' AND transfer_logs.canceled = 'false' \
GROUP BY account.apartment ORDER BY account.apartment;"
}

Expand Down
8 changes: 4 additions & 4 deletions routes/residence.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]' AND finished = 'true';", (err, result) => {
pool.query("SELECT count(id) from transfer_logs WHERE recipient = '[email protected]' 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
Expand Down Expand Up @@ -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 = '[email protected]' AND finished = 'true' \
WHERE transfer_logs.recipient = '[email protected]' AND finished = 'true' AND canceled = 'false' \
ORDER BY date DESC, recipient_username DESC OFFSET $1 LIMIT $2;",
values: [start, limit]
}
Expand Down Expand Up @@ -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 = '[email protected]' AND finished = 'true' \
WHERE recipient = '[email protected]' AND finished = 'true' AND canceled = 'false' \
ORDER BY date DESC LIMIT 4;"
}

Expand All @@ -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 = '[email protected]' AND transfer_logs.finished = 'true' \
WHERE transfer_logs.recipient = '[email protected]' AND transfer_logs.finished = 'true' AND transfer_logs.canceled = 'false' \
GROUP BY account.apartment ORDER BY account.apartment;"
}

Expand Down
8 changes: 4 additions & 4 deletions routes/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]' AND finished = 'true';", (err, result) => {
pool.query("SELECT count(id) from transfer_logs WHERE recipient = '[email protected]' 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
Expand Down Expand Up @@ -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 = '[email protected]' AND finished = 'true' \
WHERE transfer_logs.recipient = '[email protected]' AND finished = 'true' AND canceled = 'false' \
ORDER BY date DESC, recipient_username DESC OFFSET $1 LIMIT $2;",
values: [start, limit]
}
Expand Down Expand Up @@ -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 = '[email protected]' AND finished = 'true' \
WHERE recipient = '[email protected]' AND finished = 'true' AND canceled = 'false' \
ORDER BY date DESC LIMIT 4;"
}

Expand All @@ -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 = '[email protected]' AND transfer_logs.finished = 'true' \
WHERE transfer_logs.recipient = '[email protected]' AND transfer_logs.finished = 'true' AND transfer_logs.canceled = 'false' \
GROUP BY account.apartment ORDER BY account.apartment;"
}

Expand Down
1 change: 1 addition & 0 deletions views/admin/admin_user_profile.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
<select id="edit-user-role" class="validate input-need-clear" required="required" name="role">
<option value="" disabled selected>Choose a role</option>
<option value="senior_student" selected>Senior Student</option>
<option value="apartment">Apartment</option>
<option value="re">Residential Educator</option>
<option value="keeper">Keeper</option>
<option value="admin">Admin</option>
Expand Down

0 comments on commit e4547f3

Please sign in to comment.