Skip to content

Instantly share code, notes, and snippets.

@janbarasek
Created December 20, 2024 09:37
Show Gist options
  • Save janbarasek/6f897606bf06dfcecf64db5c8ad361f6 to your computer and use it in GitHub Desktop.
Save janbarasek/6f897606bf06dfcecf64db5c8ad361f6 to your computer and use it in GitHub Desktop.
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