Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed console.log entries #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
13 changes: 0 additions & 13 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ submitItemBtn.addEventListener("click", function(e) {
xhrPost.onreadystatechange = function() {
setTimeout(() => {
// horrible hacky fix for 302 redirect
console.log("submit item by lender successful!");
request("/populate-all", "GET", updateDom);
}, 500);
};
Expand All @@ -65,7 +64,6 @@ submitItemBtn.addEventListener("click", function(e) {
// var xhrPost = new XMLHttpRequest();
// xhrPost.onreadystatechange = function() {
// if (xhrPost.readyState === 4 && xhrPost.status === 200) {
// console.log("post data response successful");
// reqForm.classList.add("hidden");
// var success = document.createElement("div");
// success.innerText = "Loan requested! :)";
Expand All @@ -87,13 +85,10 @@ submitItemBtn.addEventListener("click", function(e) {
function borrow(id, name) {
// reqForm.classList.remove("hidden");
// itemIdInput.value = id;
// console.log("name: ", name);
// borrowH3.innerText = "Borrow " + name.toLowerCase();
console.log(id, name);
var xhrPost = new XMLHttpRequest();
xhrPost.onreadystatechange = function() {
if (xhrPost.readyState === 4 && xhrPost.status === 200) {
console.log("borrow data response successful");
var success = document.createElement("div");
success.innerText = "Loan requested! :)";
successDiv.appendChild(success);
Expand All @@ -119,7 +114,6 @@ function borrow(id, name) {
searchBtn.addEventListener("click", function(e) {
e.preventDefault();
var inputValue = encodeURIComponent(input.value);
console.log("input " + inputValue);

// add validation alert if buttons gets clicked without input val
if (inputValue.trim() == "") {
Expand All @@ -142,8 +136,6 @@ function updateDom(err, data) {
if (err) {
console.log(err);
} else {
console.log("updateDom reached");

var items = JSON.parse(data);
var table = document.getElementById("items-table");
clearList(table);
Expand Down Expand Up @@ -172,7 +164,6 @@ function updateDom(err, data) {

if (items.length > 0) {
items.forEach(function(item) {
console.log(item);
// adding our item names
var row = document.createElement("tr");
var name = document.createElement("td");
Expand Down Expand Up @@ -247,7 +238,6 @@ regButton.addEventListener("click", function(e) {

// checks that email is valid
if (regEmail.validity.typeMismatch || regEmail.validity.valueMissing) {
console.log("reached");
error.innerHTML = "Please enter a valid email address";
error.className = "error";
regEmail.classList.add("incorrect-field");
Expand Down Expand Up @@ -326,13 +316,10 @@ const psdLogin = document.getElementById("login-password");
const error1 = document.getElementById("error1");

emailLogin.addEventListener("focusout", function(e) {
console.log("HERE");
if (!emailLogin.validity.valid) {
//console.log('email=',emailLogin.value);console.log('here')
error1.innerHTML = "Please enter a valid email address";
error1.className = "error";
document.getElementById("login-email").classList.add("invalid-input");
console.log(emailLogin.classList);
} else if (emailLogin.validity.valid) {
emailLogin.classList.remove("invalid-input");
error1.classList.remove("error");
Expand Down
1 change: 0 additions & 1 deletion src/database/db_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const sql = fs.readFileSync(`${__dirname}/db_build.sql`).toString();
const runDbBuild = cb => {
dbConnection.query(sql, (err, res) => {
if (err) throw err;
// console.log("Tables created with result:", res);
cb(null, res);
});
};
Expand Down
25 changes: 0 additions & 25 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ const handlers = {
},

home(req, res) {
console.log("home reached");
if (req.headers.cookie) {
console.log("checking cookie");
const sessionId = req.headers.cookie.split("=")[1];
passwords.checkSession(sessionId, (err, rows) => {
if (err) {
Expand All @@ -79,15 +77,11 @@ const handlers = {
res.writeHead(401, { "Content-Type": "text/html" });
res.end("<h1>Forbidden Access</h1>");
} else {
console.log("cookie valid");
fs.readFile(buildPath("index-loggedin.html"), (err, file) => {
console.log("reading logged in html file");
if (err) {
res.writeHead(500, { "Content-Type": "text/html" });
res.end("<h1>Server Error</h1>");
console.log("home error");
} else {
console.log("returning logged in html file");
res.writeHead(200, { "Content-Type": "text/html" });
res.end(file);
}
Expand All @@ -99,7 +93,6 @@ const handlers = {
if (err) {
res.writeHead(500, { "Content-Type": "text/html" });
res.end("<h1>Server Error</h1>");
console.log("home error");
} else {
res.writeHead(200, { "Content-Type": "text/html" });
res.end(file);
Expand All @@ -109,12 +102,10 @@ const handlers = {
},

public(req, res, endpoint) {
console.log("endpoint: ", endpoint);
fs.readFile(buildPath(endpoint), (err, file) => {
if (err) {
res.writeHead(404, { "Content-Type": "text/html" });
res.end("<h1>Page not found</h1>");
console.log("public error");
} else {
res.writeHead(200, {
"Content-Type": contentType[path.extname(endpoint)]
Expand Down Expand Up @@ -152,7 +143,6 @@ const handlers = {
sessionID,
email,
(err, result, sssionID) => {
console.log("Store Session func reached");
if (err) {
res.writeHead(500, { "Content-Type": "text/html" });
res.end("<h1>Server Error in storeSession func</h1>");
Expand Down Expand Up @@ -180,7 +170,6 @@ const handlers = {
register(req, res) {
if (req.method === "POST") {
handlers.collectData(req, (err, data) => {
console.log("collected data");
if (err) {
res.writeHead(500, { "Content-Type": "text/html" });
res.end("<h1>Server Error</h1>");
Expand All @@ -190,11 +179,9 @@ const handlers = {
!data["reg-password"] ||
!data["fav-colour"]
) {
console.log("data: ", data);
res.writeHead(500, { "Content-Type": "text/html" });
res.end("<h1>Server Error</h1>");
} else {
console.log(data);
// sanitise data
const name = data["reg-name"].replace(/[^a-z0-9_\- ]/gi, "");
const email = data["reg-email"].replace(/[^a-z0-9._\-@+]/gi, "");
Expand Down Expand Up @@ -233,10 +220,7 @@ const handlers = {
sessionID,
email,
(err, result, sssionID) => {
console.log("Store Session func reached");
if (err) {
console.log("HERE");
console.log(err);
res.writeHead(500, { "Content-Type": "text/html" });
res.end(
"<h1>Server Error in storeSession func</h1>"
Expand Down Expand Up @@ -282,7 +266,6 @@ const handlers = {
if (err) {
res.writeHead(500, { "Content-Type": "text/html" });
res.end("<h1>Server Error</h1>");
console.log("search error");
} else {
res.writeHead(200, "Content-type: application/json");
res.end(JSON.stringify(result));
Expand All @@ -293,7 +276,6 @@ const handlers = {
if (req.method === "POST") {
handlers.collectJSON(req, (err, parsedData) => {
cookies.getUserDetails(req, (err, result) => {
console.log('results are in: ', result);
postData(
result.name,
result.email,
Expand All @@ -302,7 +284,6 @@ const handlers = {
if (err) {
res.writeHead(500, { "Content-Type": "text/html" });
res.end("<h1>Server Error</h1>");
console.log("postdata error");
} else {
res.writeHead(302, { Location: "/success" });
res.end();
Expand All @@ -319,7 +300,6 @@ const handlers = {
if (err) {
res.writeHead(500, { "Content-Type": "text/html" });
res.end("<h1>Server Error</h1>");
console.log("home error");
} else {
res.writeHead(200, { "Content-Type": "text/html" });
res.end(file);
Expand All @@ -329,11 +309,9 @@ const handlers = {
addItem(req, res) {
// SQL query: Add user
// SQL query: Add item from that user
console.log("addItem reached");
if (req.method === "POST") {
if (req.headers.cookie) {
const sessionId = req.headers.cookie.split("=")[1];
console.log(sessionId);
passwords.checkSession(sessionId, (err, rows) => {
if (err) {
res.writeHead(500, { "Content-Type": "text/html" });
Expand Down Expand Up @@ -368,7 +346,6 @@ const handlers = {
}
});
} else {
console.log("no cookie");
res.writeHead(401, { "Content-Type": "text/html" });
res.end("<h1>401 Forbidden</h1>");
}
Expand All @@ -388,10 +365,8 @@ const handlers = {
// if (err) {
// response.writeHead(500, "Content-Type:text/html");
// response.end("<h1>Sorry, there was a problem getting the users</h1>");
// console.log(err);
// } else {
getData("", (err, res) => {
console.log("reached again");
if (err) {
response.writeHead(500, "Content-Type:text/html");
response.end("<h1>Sorry, there was a problem getting the users</h1>");
Expand Down
3 changes: 0 additions & 3 deletions src/passwords.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const passwords = {
},

storeSession: (sessionID, email, cb) => {
console.log("session ID: ", sessionID);
passwords.deletePreviousSession(email, (err, res) => {
if (err) return cb(err);
dbConnection.query(
Expand Down Expand Up @@ -66,8 +65,6 @@ const passwords = {
`SELECT email FROM active_sessions WHERE session_id=$1`,
[sessionId],
(err, res) => {
console.log("session id: ", sessionId);
console.log("email1: ", res);
if (err) return cb(err);
return cb(null, res.rows);
}
Expand Down
1 change: 0 additions & 1 deletion src/queries/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const getPassword = (qry, cb) => {
[qry],
(err, res) => {
if (err) {
//console.log('DBQURERY');console.log(err);
return cb(err);
}
return cb(null, res.rows);
Expand Down
3 changes: 0 additions & 3 deletions src/queries/postData.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const checkUser = (email, cb) => {
`SELECT id FROM users WHERE email=$1`,
[email],
(err, res) => {
console.log('checkUser result: ', res);
if (err) return cb(err);
if (res.rowCount === 1) cb(null, res);
else cb(null, false);
Expand All @@ -48,7 +47,6 @@ const postData = (name, email, itemId, cb) => {
[name, email],
(err, res) => {
if (err) {
console.log(err);
return cb(err);
}
borrowerId = res.rows[0].id;
Expand All @@ -60,7 +58,6 @@ const postData = (name, email, itemId, cb) => {
};

const addItem = (name, description, lenderId, cb) => {
console.log("add item reached");
dbConnection.query(
`INSERT INTO items (name, description, lender_id) VALUES ('${name}', '${description}', ${lenderId}) RETURNING id`,
(err, res) => {
Expand Down
3 changes: 0 additions & 3 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ const router = (req, res) => {
} else if (endpoint.startsWith("search?q=")) {
handlers.search(req, res, endpoint); // some arguments maybe
} else if (endpoint === "register") {
console.log("reached register");
handlers.register(req, res);
} else if (endpoint === "request-item") {
handlers.requestItem(req, res);
} else if (endpoint === "add-item") {
console.log("add-item");
handlers.addItem(req, res, endpoint); // some arguments
} else if (endpoint === "populate-all") {
console.log("populate");
handlers.testData(req, res);
} else if (endpoint === "success") {
handlers.success(req, res);
Expand Down