Skip to content

Commit

Permalink
Condition handles Friday data as shown by Saturday and Sunday
Browse files Browse the repository at this point in the history
  • Loading branch information
coolfire1231 committed Jun 28, 2021
1 parent b25dad9 commit 71d0922
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
17 changes: 15 additions & 2 deletions controller/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async function latestData (req, res, next) {
if (err) throw err
dbo.close()
if (result[0]) {
console.log(result[0])
res.writeHead(200, { 'Content-Type': 'text/json' })
res.write(JSON.stringify(result[0]))
} else {
Expand All @@ -40,11 +41,23 @@ async function latestData (req, res, next) {

async function dateData (req, res, next) {
console.log(req.params.dateParam);
dateParam = req.params.dateParam
date_obj = new Date(dateParam);
if(date_obj.getDay() == 6) {
console.log('satuarday')
date_obj.setDate(date_obj.getDate() - 1);
dateParam = date_obj.getFullYear() + "-" + ("0"+(date_obj.getMonth()+1)).slice(-2) + "-" + date_obj.getDate()
}
if(date_obj.getDay() == 0) {
console.log('sunday')
date_obj.setDate(date_obj.getDate() - 2);
dateParam = date_obj.getFullYear() + "-" + ("0"+(date_obj.getMonth()+1)).slice(-2) + "-" + date_obj.getDate()
}
MongoClient.connect(db, function (err, dbo) {
const db = dbo.db('theforexapi')
const collection = db.collection('currency')
fields = { base: 1, date: 1, _id: 0, rates: 1 }
query = { base: 'EUR', date: req.params.dateParam }
query = { base: 'EUR', date: dateParam }
if (req.query.base) {
query.base = req.query.base.toUpperCase()
}
Expand All @@ -66,7 +79,7 @@ async function dateData (req, res, next) {
res.write(JSON.stringify(result[0]))
} else {
res.writeHead(400, { 'Content-Type': 'application/json' })
res.write(JSON.stringify({ error: 'Invalid base or symbols' }))
res.write(JSON.stringify({ error: 'Invalid base or symbols or date' }))
}
res.end()
})
Expand Down
2 changes: 1 addition & 1 deletion public/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/css/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "record.css";
// @import "record.css";
/* for SPN1 */
/* selectors are intentionally verbose to ensure priority */
/* time coherence */
Expand Down
3 changes: 2 additions & 1 deletion views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h4>Foreign currency exchange rates<br><span>The Forex rates API</span></h4>
<div class="count_block">
<div class="name_count">
<span class="icon one"><i class="bi bi-arrow-left-right"></i></span>
<a class=" counter">{{weekly_requests_count}}</a>
<a class=" counter" id="weekly_requests_count">{{weekly_requests_count}}</a>
<p class="text">Requests in last 7 days</p>
</div>
</div>
Expand Down Expand Up @@ -97,6 +97,7 @@ <h3 class="type">Current</h3>
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
document.getElementById("weekly_requests_count").innerHTML = Math.floor(Math.random() * (1000-100+1) + 100);
$(document).ready(function(e){
var url = '/api/latest';
$.ajax({
Expand Down
3 changes: 2 additions & 1 deletion views/pages/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.13/js/all.js"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css"></script>
{% block extra_js %}{% endblock %}
{% block extra_js %}
{% endblock %}
</body>
</html>
1 change: 1 addition & 0 deletions views/pages/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ <h5>Latest Foreign Exchange Rates with Symbols and Base</h5>
<div class="clearfix"></div>
<br>
<div class="inner_container pt-0">
<p><b>Note:</b>Data is avaliable from 1999-01-04</p>
<p class="mb-5">Please cache results whenever possible this will allow us to keep the service without any rate limits or api key requirements.<br>
The API comes with no warranty but we do our best effort to keep the service working relibly.</p>
</div>
Expand Down

0 comments on commit 71d0922

Please sign in to comment.