From 8bcccc7c1bb9a795a71d5664f1030620b1f075a8 Mon Sep 17 00:00:00 2001 From: Ludo Date: Sun, 6 Jul 2025 22:57:12 +0000 Subject: [PATCH] =?UTF-8?q?Nahr=C3=A1t=20soubory=20do=20=E2=80=9E/?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 server.js diff --git a/server.js b/server.js new file mode 100644 index 0000000..194da35 --- /dev/null +++ b/server.js @@ -0,0 +1,62 @@ +// Node.js API server to fetch and merge Slovak company data by IČO +// from two Finančná správa SR API endpoints + +const express = require("express"); +const axios = require("axios"); + +const app = express(); +const PORT = 3000; + +// Insert your API key below +const API_KEY = "2t5lK487ces7Rc4oEHrIwCjB5DpoZUBChQxCLBiSrwGNdEubKpraAtQLEiJmPXkdjNw5FssYpuO0LXSZpk3U6oqePyFaIGHokg4WNPEM0302X2BK4iXpkFv9Qg7jyeUXh50bWVExVrVSBuOnOQpBzzdJ1k1D54b115MD3y5ticWxvGDLUaqLQgA6nzFgbYOx6dR0ToJUxU714TetLBZCBy0xKSnBaOrxYv10I1gZ1q4rQx4Q8k7BTR6MaP"; + +// API endpoint: /api/lookup?ico=XXXXXXXX +app.get("/api/lookup", async (req, res) => { + const ico = req.query.ico; + + if (!ico) { + return res.status(400).json({ error: "Missing ICO parameter" }); + } + + const endpoints = [ + `https://iz.opendata.financnasprava.sk/api/data/ds_dsrdp/search?page=1&column=ico&search=${ico}`, + `https://iz.opendata.financnasprava.sk/api/data/ds_dphs/search?page=1&column=ico&search=${ico}` + ]; + + try { + // Fetch both endpoints in parallel + const [res1, res2] = await Promise.all(endpoints.map(url => + axios.get(url, { + headers: { + accept: "application/json", + key: API_KEY + } + }) + )); + + const data1 = res1.data?.data || []; + const data2 = res2.data?.data || []; + + // Combine and deduplicate by IČO or ID if available + const merged = [...data1, ...data2].filter( + (item, index, self) => + index === self.findIndex((t) => + JSON.stringify(t) === JSON.stringify(item) + ) + ); + + // Return merged, deduplicated result + res.json({ + source1_count: data1.length, + source2_count: data2.length, + merged_count: merged.length, + data: merged + }); + } catch (error) { + res.status(500).json({ error: error.message }); + } +}); + +app.listen(PORT, () => { + console.log(`API server running at http://localhost:${PORT}`); +}); \ No newline at end of file