-
Notifications
You must be signed in to change notification settings - Fork 0
/
tickets.js
52 lines (39 loc) · 1.11 KB
/
tickets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const axios = require("axios");
const nycTicketDataUrl =
"https://data.cityofnewyork.us/resource/nc67-uf89.json";
function forceUpperCase(str) {
split_str = str.split("");
updatedPlate = [];
for (let char of split_str) {
if (char.match(/[a-z]/i)) {
updatedPlate.push(char.toUpperCase());
} else {
updatedPlate.push(char);
}
}
return updatedPlate.join("");
}
async function getApiData(licensePlate) {
licenseQueryStr = "?plate=";
fullUrl = nycTicketDataUrl + licenseQueryStr + licensePlate;
let { data } = await axios.get(fullUrl);
return data;
}
async function getParkingDataByLic(licensePlate) {
let formatPlate = forceUpperCase(licensePlate);
let apiData = await getApiData(formatPlate);
return apiData;
}
async function getTotalCost(licensePlate) {
let formatPlate = forceUpperCase(licensePlate);
let apiData = await getApiData(formatPlate);
let paymentAmount = 0
for (const [key,value] of Object.entries(apiData)) {
paymentAmount += +value["payment_amount"]
}
return paymentAmount;
}
module.exports = {
getParkingDataByLic,
getTotalCost
};