Skip to content

Commit

Permalink
Merge pull request #29 from FACN7/ebraheem
Browse files Browse the repository at this point in the history
sending data to dom Relates #28
  • Loading branch information
ebraheemabbas authored Oct 30, 2019
2 parents e3cb7e6 + 659206d commit e297fff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
24 changes: 15 additions & 9 deletions public/private.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
function request(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = () => resolve(xhr.responseText);
xhr.onerror = () => reject(xhr.statusText);
xhr.send();
});
function request(url, cb) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
cb(null, xhr.responseText);
} else {
cb("error" + xhr.responseType);
}
}
};
xhr.open("GET", url, true);
xhr.send();
}


function showTransactionsListDom(err, data) {
if (err) {
Expand All @@ -21,7 +27,7 @@ function request(url) {
row.appendChild(date);
var desc = document.createElement("td");
desc.innerHTML = tran.descrip;
row.appendChild(date);
row.appendChild(desc);
var balance = document.createElement("td");
balance.innerHTML = tran.balance;
row.appendChild(balance);
Expand Down
21 changes: 11 additions & 10 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const serverError = (err, response) => {


const homeHandler = (request,response) => {
if (request.headers.cookie){
if (request.headers.cookie&&userid!==undefined){
const { jwt } = parse(request.headers.cookie);
console.log(jwt);
verify(jwt, SECRET, (err, jwt) => {
Expand Down Expand Up @@ -228,7 +228,7 @@ const homeHandler = (request,response) => {


const transactionsHandler=(request,response)=>{
if (request.headers.cookie){
if (request.headers.cookie&&userid!==undefined){
const { jwt } = parse(request.headers.cookie);
console.log(jwt);
verify(jwt, SECRET, (err, jwt) => {
Expand All @@ -238,16 +238,16 @@ const homeHandler = (request,response) => {
// check user
const message = `Your user id is: ${jwt.email}`;
if(userid.email===jwt.email){
transactions(userid.email).then((err,res)=>{
if (err) return console.log(err);
let dynmicData = JSON.stringify(res);
transactions_query(userid.email).then((res)=>{
let dynmicData = JSON.stringify(res.rows);
response.writeHead(200, { "Content-Type": "application/json" });
// console.log(dynmicData);

response.end(dynmicData);
console.log(dynmicData);
})
}).catch(err => console.log(err))

}{
console.log("hackers")
}else{
console.log("hackerstrans")
}
}
});
Expand All @@ -260,5 +260,6 @@ module.exports = {
publicHandler,
errorHandler,
loginHandler,
signUpHandler
signUpHandler,
transactionsHandler
};
4 changes: 2 additions & 2 deletions src/router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { homeHandler,
publicHandler,
errorHandler,loginHandler,signUpHandler} = require("./handlers");
errorHandler,loginHandler,signUpHandler,transactionsHandler} = require("./handlers");


const router = (request, response) => {
Expand All @@ -22,7 +22,7 @@ const router = (request, response) => {
} else if (url === "/add-trnasaction") {

} else if (url === "/transactions") {

transactionsHandler(request,response)
}else if (url === "/delete-trnasaction") {
} else {
errorHandler(response);
Expand Down

0 comments on commit e297fff

Please sign in to comment.