Skip to content

Commit

Permalink
refactor: generalize symbol variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Apr 17, 2024
1 parent 09198d8 commit 09ea878
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/content/quoteRecords/_scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ for (const rateRow of rateRows) {
}

for (const [currency, rateByDate] of rateByDateByCurrency) {
const symbol = currencyPair(currency, QUOTE_CURRENCY);
await using file = await fs.open(
new URL(
"./" + currencyPair(currency, QUOTE_CURRENCY) + ".json",
import.meta.url,
),
new URL("./" + symbol + ".json", import.meta.url),
fs.constants.O_RDWR | fs.constants.O_CREAT,
);

Expand Down
14 changes: 7 additions & 7 deletions src/pages/api/v1/years/index.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getCollection } from "astro:content";

const quoteRecords = await getCollection("quoteRecords");

const currencyPairsByYear = new Map<number, string[]>();
const symbolsByYear = new Map<number, string[]>();
for (const quoteRecord of quoteRecords) {
const years = [
...new Set(
Expand All @@ -13,14 +13,14 @@ for (const quoteRecord of quoteRecords) {
),
];
for (const year of years) {
let currencyPairs = currencyPairsByYear.get(year);
if (currencyPairs == null) {
currencyPairs = [];
currencyPairsByYear.set(year, currencyPairs);
let symbols = symbolsByYear.get(year);
if (symbols == null) {
symbols = [];
symbolsByYear.set(year, symbols);
}
currencyPairs.push(quoteRecord.id);
symbols.push(quoteRecord.id);
}
}

export const GET: APIRoute = () =>
Response.json(Object.fromEntries(currencyPairsByYear));
Response.json(Object.fromEntries(symbolsByYear));

0 comments on commit 09ea878

Please sign in to comment.