-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,144 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import type { Request, Response } from "express"; | ||
import { get } from "../helpers/HttpClient.ts"; | ||
import type {Request, Response} from "express"; | ||
import {get} from "../helpers/HttpClient.ts"; | ||
import dotenv from "dotenv"; | ||
import type { Stock } from "../types/BrapiDev/Stock.ts"; | ||
import type {Stock} from "../types/BrapiDev/Stock.ts"; | ||
dotenv.config(); | ||
|
||
const BASE_API_URL = process.env.BRAPI_HOST as string; | ||
const API_KEY = process.env.BRAPI_KEY as string; | ||
|
||
const defaultHeaders = { | ||
"Accept-Encoding": "deflate, gzip", | ||
"referrer-policy": "origin-when-cross-origin", | ||
"X-Api-Key": API_KEY, | ||
"Accept-Encoding": "deflate, gzip", | ||
"referrer-policy": "origin-when-cross-origin", | ||
"X-Api-Key": API_KEY, | ||
}; | ||
|
||
interface QueryParams { | ||
limit?: number; | ||
page?: number; | ||
limit?: number; | ||
page?: number; | ||
} | ||
|
||
interface ResponseData { | ||
stocks: Stock[]; | ||
interface ResponseListStocks { | ||
stocks: Stock[]; | ||
} | ||
|
||
/** | ||
* Handles the request to get the stocks listing. | ||
* @description Handles the request to get the stocks listing. | ||
* | ||
* @param {Request} req - The request object | ||
* @param {Response} res - The response object | ||
* @returns {void} | ||
* @throws {Error} If the request to the external API fails | ||
*/ | ||
export async function listStocks(req: Request, res: Response): Promise<void> { | ||
const { limit = 12, page = 1 }: QueryParams = req.query; | ||
const url = `${BASE_API_URL}/api/quote/list?limit=${limit}&page=${page}`; | ||
const {limit = 12, page = 1}: QueryParams = req.query; | ||
const url = `${BASE_API_URL}/api/quote/list?limit=${limit}&page=${page}`; | ||
|
||
try { | ||
const response = await get(url, defaultHeaders); | ||
try { | ||
const response = await get(url, defaultHeaders); | ||
|
||
if (!response.ok) throw new Error(await response.json()); | ||
if (!response.ok) throw new Error(await response.json()); | ||
|
||
const jsonData: ResponseData = await response.json(); | ||
const jsonData: ResponseListStocks = await response.json(); | ||
|
||
res.status(200).json(jsonData.stocks); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ error: error }); | ||
} | ||
res.status(200).json(jsonData.stocks); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({error: error}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type {Request, Response} from "express"; | ||
import {get} from "../helpers/HttpClient.ts"; | ||
import type {CurrencyQuotes} from "../types/CurrencyQuotes/CurrencyQuotes.ts"; | ||
|
||
const BASE_API_URL = process.env.CURRENCYQUOTES_HOST as string; | ||
|
||
/** | ||
* @description Handles the request to get the list of currency quotes. | ||
* | ||
* @param {Request} req - The request object | ||
* @param {Response} res - The response object | ||
* @returns {void} | ||
* @throws {Error} If the request to the external API fails | ||
*/ | ||
export async function listCurrencyQuotes(req: Request, res: Response): Promise<void> { | ||
const url = `${BASE_API_URL}/api/latest.json`; | ||
|
||
try { | ||
const response = await get(url); | ||
|
||
if (!response.ok) throw new Error(await response.json()); | ||
|
||
const jsonData: CurrencyQuotes = await response.json(); | ||
|
||
res.json(jsonData); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({error: error}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from "express"; | ||
import {listCurrencyQuotes} from "../proxy/CurrencyQuotes.ts"; | ||
|
||
const currencyQuotesRoutes = express(); | ||
|
||
currencyQuotesRoutes.get("/api/latest.json", listCurrencyQuotes); | ||
|
||
export default currencyQuotesRoutes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export interface Stock { | ||
stock: string; | ||
name: string; | ||
close: number; | ||
change: number; | ||
volume: number; | ||
market_cap: number; | ||
logo: string; | ||
sector: string; | ||
type: string; | ||
stock: string; | ||
name: string; | ||
close: number; | ||
change: number; | ||
volume: number; | ||
market_cap: number; | ||
logo: string; | ||
sector: string; | ||
type: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type {Rates} from "./Rates"; | ||
|
||
export interface CurrencyQuotes { | ||
table: string; | ||
rates: Rates; | ||
lastupdate: string; // ISO 8601 date string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
export interface Rates { | ||
AED: number; | ||
AFN: number; | ||
ALL: number; | ||
AMD: number; | ||
ANG: number; | ||
AOA: number; | ||
ARS: number; | ||
AUD: number; | ||
AWG: number; | ||
AZN: number; | ||
BAM: number; | ||
BBD: number; | ||
BDT: number; | ||
BGN: number; | ||
BHD: number; | ||
BIF: number; | ||
BMD: number; | ||
BND: number; | ||
BOB: number; | ||
BRL: number; | ||
BSD: number; | ||
BTC: number; | ||
BTN: number; | ||
BTS: number; | ||
BWP: number; | ||
BYN: number; | ||
BZD: number; | ||
CAD: number; | ||
CDF: number; | ||
CHF: number; | ||
CLF: number; | ||
CLP: number; | ||
CNH: number; | ||
CNY: number; | ||
COP: number; | ||
CRC: number; | ||
CUC: number; | ||
CUP: number; | ||
CVE: number; | ||
CZK: number; | ||
DASH: number; | ||
DJF: number; | ||
DKK: number; | ||
DOGE: number; | ||
DOP: number; | ||
DZD: number; | ||
EGP: number; | ||
ERN: number; | ||
ETB: number; | ||
ETH: number; | ||
EUR: number; | ||
FJD: number; | ||
FKP: number; | ||
GBP: number; | ||
GEL: number; | ||
GGP: number; | ||
GHS: number; | ||
GIP: number; | ||
GMD: number; | ||
GNF: number; | ||
GTQ: number; | ||
GYD: number; | ||
HKD: number; | ||
HNL: number; | ||
HRK: number; | ||
HTG: number; | ||
HUF: number; | ||
IDR: number; | ||
ILS: number; | ||
IMP: number; | ||
INR: number; | ||
IQD: number; | ||
IRR: number; | ||
ISK: number; | ||
JEP: number; | ||
JMD: number; | ||
JOD: number; | ||
JPY: number; | ||
KES: number; | ||
KGS: number; | ||
KHR: number; | ||
KMF: number; | ||
KPW: number; | ||
KRW: number; | ||
KWD: number; | ||
KYD: number; | ||
KZT: number; | ||
LAK: number; | ||
LBP: number; | ||
LD: number; | ||
LKR: number; | ||
LRD: number; | ||
LSL: number; | ||
LTC: number; | ||
LYD: number; | ||
MAD: number; | ||
MDL: number; | ||
MGA: number; | ||
MKD: number; | ||
MMK: number; | ||
MNT: number; | ||
MOP: number; | ||
MRO: number; | ||
MRU: number; | ||
MUR: number; | ||
MVR: number; | ||
MWK: number; | ||
MXN: number; | ||
MYR: number; | ||
MZN: number; | ||
NAD: number; | ||
NGN: number; | ||
NIO: number; | ||
NOK: number; | ||
NPR: number; | ||
NXT: number; | ||
NZD: number; | ||
OMR: number; | ||
PAB: number; | ||
PEN: number; | ||
PGK: number; | ||
PHP: number; | ||
PKR: number; | ||
PLN: number; | ||
PYG: number; | ||
QAR: number; | ||
RON: number; | ||
RSD: number; | ||
RUB: number; | ||
RWF: number; | ||
SAR: number; | ||
SBD: number; | ||
SCR: number; | ||
SDG: number; | ||
SEK: number; | ||
SGD: number; | ||
SHP: number; | ||
SLL: number; | ||
SOS: number; | ||
SRD: number; | ||
SSP: number; | ||
STD: number; | ||
STN: number; | ||
STR: number; | ||
SVC: number; | ||
SYP: number; | ||
SZL: number; | ||
THB: number; | ||
TJS: number; | ||
TMT: number; | ||
TND: number; | ||
TOP: number; | ||
TRY: number; | ||
TTD: number; | ||
TWD: number; | ||
TZS: number; | ||
UAH: number; | ||
UGX: number; | ||
USD: number; | ||
UYU: number; | ||
UZS: number; | ||
VEF_BLKMKT: number; | ||
VEF_DICOM: number; | ||
VEF_DIPRO: number; | ||
VES: number; | ||
VND: number; | ||
VUV: number; | ||
WST: number; | ||
XAF: number; | ||
XAG: number; | ||
XAU: number; | ||
XCD: number; | ||
XDR: number; | ||
XMR: number; | ||
XOF: number; | ||
XPD: number; | ||
XPF: number; | ||
XPT: number; | ||
XRP: number; | ||
YER: number; | ||
ZAR: number; | ||
ZMW: number; | ||
ZWL: number; | ||
NMC: number; | ||
PPC: number; | ||
NVC: number; | ||
XPM: number; | ||
EAC: number; | ||
VTC: number; | ||
EMC: number; | ||
FCT: number; | ||
} |
Oops, something went wrong.