Skip to content

Commit 22ea53a

Browse files
authored
Merge pull request #3 from michaelNgiri/housekeeping
reconcile branch Housekeeping with master
2 parents 2b90c09 + 2a078cf commit 22ea53a

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Fetch-API-Client
2-
A front end client that makes request to a backend API using fetch
2+
An ES6 front end API client that makes request to a backend API using fetch
33

4-
homepage: http://devpool-client.herokuapp.com
4+
homepage: http://devpool-client.herokuapp.com
5+
6+
7+
8+
[![Maintainability](https://api.codeclimate.com/v1/badges/c15ab3b0f6907b1526ce/maintainability)](https://codeclimate.com/github/michaelNgiri/Fetch-API-Client/maintainability)

scripts/app.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,16 @@ function fetchRecentQuestionAnswers(id){
4040
}
4141

4242

43+
44+
4345
function saveAnswer(questionId) {
44-
questionId = findDom('featured-question-id').value;
45-
console.log(questionId);
46+
questionId = findDom('featured-question-id').value;
4647
const userId = findDom('featured-question-user-id').value;
47-
console.log(userId);
4848
const answer = findDom('answer-body').value;
49-
console.log(answer);
50-
5149
const answerUrl = baseUrl+'questions/answers';
5250
const queryBody = 'question_id='+questionId+'&user_id='+userId+'&answer='+answer;
53-
console.log(queryBody);
54-
5551
//check if valid characters are entered in answer text
5652
if (typeof answer === "string" && answer.trim().length >= 5) {
57-
58-
5953
fetch(answerUrl,
6054
{
6155
method: 'post',
@@ -73,21 +67,12 @@ fetch(answerUrl,
7367
}else{
7468
indicateError();
7569
}
76-
// Work with JSON data here
77-
console.log(data['message']);
7870
}).catch(err => {
7971
console.log(err);
8072
// Do something for an error here
8173
});
82-
83-
console.log(answerUrl);
84-
8574
}else{
86-
console.log('invalid answer text');
87-
const answerStatus = findDom('answer-status');
88-
answerStatus.innerHTML = 'please type at least 5 characters';
89-
answerStatus.style.color='orange';
90-
answerStatus.style.visibility='visible';
75+
showAnswerSaveError();
9176
}
9277
}
9378

@@ -114,4 +99,12 @@ function indicateError(){
11499
const answerStatus = findDom('answer-status');
115100
answerStatus.innerHTML = 'Failed to save! Login and try again';
116101
answerStatus.style.visibility='visible';
102+
}
103+
104+
function showAnswerSaveError(){
105+
console.log('invalid answer text');
106+
const answerStatus = findDom('answer-status');
107+
answerStatus.innerHTML = 'please type at least 5 characters';
108+
answerStatus.style.color='orange';
109+
answerStatus.style.visibility='visible';
117110
}

scripts/auth.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11

22
function submitLogin(){
3-
const x = document.getElementById('password').value.toString().trim();
4-
const y = document.getElementById('email').value.toString().trim();
3+
const password = document.getElementById('password').value.toString().trim();
4+
const email = document.getElementById('email').value.toString().trim();
55
//console.log(x);
66
// console.log(y);
7-
const body = 'email'+'='+y+'&'+'password'+'='+x;
8-
const url = baseUrl+"auth/login";
7+
const body = 'email'+'='+email+'&'+'password'+'='+password;
8+
const loginUrl = baseUrl+"auth/login";
99
//console.log(body);
1010
//const data = {"email":y, password:x};
11-
postQuery(url, body)
11+
postQuery(loginUrl, body)
1212
}
1313

14-
function postQuery(url, body) {
14+
function postQuery(loginUrl, body) {
1515
if (!('fetch' in window)) {
1616
console.log('Fetch API not found, try including the polyfill');
1717
alert('fetch is disabled in your browser');
1818
return;
1919
}
20-
fetch(url,
20+
fetch(loginUrl,
2121
{
2222
method: 'post',
2323
headers: {

scripts/misc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//const baseUrl = 'http://localhost:3000/api/v1/';
2-
const baseUrl = 'https://dev-pool.herokuapp.com/api/v1/';
1+
const baseUrl = 'http://localhost:3000/api/v1/';
2+
//const baseUrl = 'https://dev-pool.herokuapp.com/api/v1/';
33

44
const authText = findDom('auth-text');
55
let Authorization,

0 commit comments

Comments
 (0)