organic: Add extended API
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<title>Bio Zertifikate</title>
|
||||
<script>
|
||||
async function operatorDetailsEasyCert(db, id) {
|
||||
const res = await fetch(`/organic/external/easy-cert/operators/${db}:${id}`);
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function listOperatorsEasyCert(country, postalCode) {
|
||||
const res = await fetch(`/organic/external/easy-cert/operators?country=${country}&postalCode=${postalCode}`);
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
const data = await res.json();
|
||||
const details = await Promise.all(data.data.map(op => operatorDetailsEasyCert(op.db, op.id)));
|
||||
for (let i = 0; i < details.length; i++) {
|
||||
data.data[i].details = details[i];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
async function operatorDetailsBioc(id) {
|
||||
const res = await fetch(`/organic/external/bioc/operators/${id}`);
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function listOperatorsBioc(country, postalCode) {
|
||||
const res = await fetch(`/organic/external/bioc/operators?country=${country}&postalCode=${postalCode}`);
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
const data = await res.json();
|
||||
const details = await Promise.all(data.data.map(op => operatorDetailsBioc(op.id)));
|
||||
for (let i = 0; i < details.length; i++) {
|
||||
data.data[i].details = details[i];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
async function listOperatorsBioQs(country, postalCode) {
|
||||
const res = await fetch(`/organic/external/bioqs/operators?country=${country}&postalCode=${postalCode}`);
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function listOperatorsLkv(postalCode) {
|
||||
const res = await fetch(`/organic/external/lkv/operators?postalCode=${postalCode}`);
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function listOperators(country, postalCode) {
|
||||
const res = await fetch(`/organic/operators?country=${country}&postalCode=${postalCode}`);
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
const operators = (await res.json()).data;
|
||||
operators.sort((a, b) => (a.name ?? "").localeCompare(b.name));
|
||||
console.log(...operators);
|
||||
return operators;
|
||||
}
|
||||
|
||||
async function operatorDetails(ooId) {
|
||||
const res = await fetch(`/organic/operators/${ooId}`);
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function search(country, postalCode) {
|
||||
for (const t of document.getElementsByClassName("operators")) document.body.removeChild(t);
|
||||
for (const t of document.getElementsByClassName("certificates")) document.body.removeChild(t);
|
||||
for (const t of document.getElementsByTagName("p")) document.body.removeChild(t);
|
||||
const operators = await listOperators(country, postalCode);
|
||||
const tbl = document.createElement("table");
|
||||
tbl.className = "operators";
|
||||
for (const op of operators) {
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `
|
||||
<td>${op.name ?? '-'}</td>
|
||||
<td>${op.lfbisNr ?? '-'}</td>
|
||||
<td>${op.id ?? '-'}</td>
|
||||
<td>${op.address ?? '-'}</td>
|
||||
<td>${op.postalCode ?? '-'}</td>
|
||||
<td>${op.city ?? '-'}</td>
|
||||
<td>${op.countryCode ?? '-'}</td>
|
||||
<td><button onclick="details('${op.id}')">Details</button></td>`;
|
||||
tbl.appendChild(tr);
|
||||
}
|
||||
document.body.appendChild(tbl);
|
||||
}
|
||||
|
||||
async function details(ooId) {
|
||||
for (const t of document.getElementsByTagName("p")) document.body.removeChild(t);
|
||||
for (const t of document.getElementsByClassName("certificates")) document.body.removeChild(t);
|
||||
const data = await operatorDetails(ooId)
|
||||
console.log(data);
|
||||
const p = document.createElement("p");
|
||||
p.innerHTML = '';
|
||||
document.body.appendChild(p);
|
||||
|
||||
for (const cert of data.certificates) {
|
||||
p.innerHTML += `Zertifikat: ${cert.nr} ${cert.id} <a href="${cert.tracesPdfUrl}" target="_blank">Traces</a> / <a href="${cert.appendixPdfUrl}" target="_blank">Anhang</a> (${cert.validFrom}-${cert.validTo})<br/>`;
|
||||
}
|
||||
|
||||
const certs = await Promise.all(data.certificates.map(async c => {
|
||||
const res = await fetch(`/organic/pdf?format=json&url=${encodeURIComponent(c.pdfUrl)}`);
|
||||
return await res.json();
|
||||
}));
|
||||
|
||||
const tbl = document.createElement("table");
|
||||
tbl.className = "certificates";
|
||||
for (const cert of certs) {
|
||||
if (cert.type === "unknown") continue;
|
||||
console.log(cert);
|
||||
const op = cert.operator;
|
||||
const auth = cert.authority;
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `
|
||||
<td>${cert.id ?? '-'}</td>
|
||||
<td>${cert.nr ?? '-'}</td>
|
||||
<td>${cert.validFrom}<br/>${cert.validTo}</td>
|
||||
<td>${op.name}<br/>${op.address}<br/>${op.postalCode} ${op.city} (${op.countryCode})</td>
|
||||
<td>${op.id ?? '-'}</td>`;
|
||||
tbl.appendChild(tr);
|
||||
}
|
||||
|
||||
document.body.appendChild(tbl);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Bio Zertifikate</h1>
|
||||
<form onsubmit="search('AT', this.postalCode.value).then(); return false;">
|
||||
<input type="text" name="postalCode" placeholder="PLZ"/>
|
||||
<button type="submit">Suchen</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user