Skip to content

Commit

Permalink
ability to update loan amount indetails page; fix widgets width under…
Browse files Browse the repository at this point in the history
… mobile in discovery page
  • Loading branch information
sammdu committed Dec 12, 2021
1 parent 6caa78f commit 72b040d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
3 changes: 2 additions & 1 deletion css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ main > aside {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
justify-content: stretch;
align-items: flex-start;
align-content: flex-start;
column-gap: 2rem;
row-gap: 2rem;
}

main > aside > section {
flex-grow: 1;
background-color: #ffffff;
width: 40%;
min-width: 20rem;
Expand Down
1 change: 1 addition & 0 deletions details.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ <h3>Powered by:</h3>
</footer>

<!-- Mustache templates below; rendered in JavaScript -->

<script type="text/html" id="tmpl_LoanOffer">
<li class="loan-offer-entry" name="{{offer_id}}">
<a href="./details.html?user_id={{user_id}}&offerSelected={{offer_id}}">
Expand Down
32 changes: 27 additions & 5 deletions js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var api = {
},

getClaimedOffers: async function(userID) {
// send the search query to the backend API
// send the claimed offers query to the backend API
const response = await fetch(this.API_URL + '/getClaimedOffers?user_id=' + userID);

// retrieve the returned cars/offers
Expand All @@ -70,12 +70,12 @@ var api = {
},

getOfferDetails: async function(userID, OfferID) {
// send the search query to the backend API
// send the offer details query to the backend API
const response = await fetch(
this.API_URL + '/getOfferDetails?user_id=' + userID + '&offer_id=' + OfferID
);

// retrieve the returned cars/offers
// retrieve the offer details
const results = await response.json();

if (response.status == 200) {
Expand All @@ -88,7 +88,7 @@ var api = {
},

claimOffer: async function(userID, OfferID) {
// send the search query to the backend API
// send the claim query to the backend API
const response = await fetch(
this.API_URL + '/claimOffer?user_id=' + userID + '&offer_id=' + OfferID
);
Expand All @@ -103,7 +103,7 @@ var api = {
},

unclaimOffer: async function(userID, OfferID) {
// send the search query to the backend API
// send the unclaim query to the backend API
const response = await fetch(
this.API_URL + '/unclaimOffer?user_id=' + userID + '&offer_id=' + OfferID
);
Expand All @@ -115,5 +115,27 @@ var api = {
console.log(response);
throw "HTTP status: " + response.status;
}
},

updateLoanAmount: async function(userID, OfferID, loanAmount) {
// send the search query to the backend API
const response = await fetch(
this.API_URL + '/updateLoanAmount?user_id=' + userID + '&offer_id=' + OfferID +
'&loan_amount=' + loanAmount
);

// retrieve the new offer details
const results = await response.json();

if (response.status == 200) {
return results;
}
else if (response.status == 406) {
return {'error': 'New principal does not result in a loan offer!'};
}
else {
console.log(response);
throw "HTTP status: " + response.status;
}
}
};
29 changes: 28 additions & 1 deletion js/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,34 @@ async function submitNewPrincipal() {
const formNewPrincipal = document.getElementById('form-update-principal');
const newPrincipal = (new FormData(formNewPrincipal)).get('loan-principal');

console.log("update principal: " + newPrincipal);
// attempt to update the specified offer's loan amount and fetch its details from the
// backend API
try {
// fetch the user_id from the URL
let userID = fetchQueryParamByKey('user_id');
// fetch the offerSelected from the URL
let offerID = fetchQueryParamByKey('offerSelected');

// make the API call
let details = await api.updateLoanAmount(userID, offerID, newPrincipal);

// if the new loan amount does not lead to an offer, alert the user, and don't
// make changes
if ('error' in details) {
alert(details['error']);
}
else {
// display the offer details
renderOfferDetails(
details['brand'], details['model'], details['year'], details['kms'],
details['price'], details['loan_amount'], details['interest_rate'],
details['term_mo'], details['total_sum']
)
}
}
catch (e) {
console.log(e);
}
}


Expand Down

0 comments on commit 72b040d

Please sign in to comment.