Created
December 20, 2024 09:37
-
-
Save janbarasek/6f897606bf06dfcecf64db5c8ad361f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const checkDph = async (dic: string) => { | |
if (!dic.startsWith('CZ')) { | |
throw new Error('DIČ musí začínat "CZ".'); | |
} | |
const baseUrl = 'https://adisreg.mfcr.cz/adistc/adis/idpr_pub/dph'; | |
const url = `${baseUrl}/pokles`; | |
try { | |
const response = await axios.get(url, { | |
params: { dic }, | |
headers: { | |
'User-Agent': 'Node.js App', | |
}, | |
}); | |
// Prozkoumání odpovědi | |
if (response.status === 200 && response.data) { | |
// Zpracování odpovědi dle struktury | |
if (response.data.includes('Nespolehlivý plátce')) { | |
return 'Nespolehlivý plátce DPH'; | |
} else if (response.data.includes('není veden jako nespolehlivý plátce')) { | |
return 'Spolehlivý plátce DPH'; | |
} else { | |
return 'Nelze určit spolehlivost plátce.'; | |
} | |
} else { | |
throw new Error('Nepodařilo se získat informace z registru DPH.'); | |
} | |
} catch (error) { | |
throw new Error(`Chyba při komunikaci s registrem DPH: ${error.message}`); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment