Files
online-energieausweis/src/components/Verbrauchsausweis/audits/PlzNichtErkannt.ts
2024-11-24 13:12:58 +11:00

30 lines
678 B
TypeScript

import { GebaeudeAufnahmeClient } from "#components/Ausweis/types.js";
import { client } from "src/trpc.js";
import { memoize } from "src/lib/Memoization.js";
import { AuditType, hidden } from "../audits/hidden.js";
export const auditPlzNichtErkannt = memoize(
async (gebaeude: GebaeudeAufnahmeClient) => {
if (gebaeude.plz) {
if (gebaeude.plz.length == 5) {
try {
const result = await client.v1.postleitzahlen.query({
plz: gebaeude.plz,
limit: 1,
});
if (result.length > 0) {
return false;
}
} catch (e) {
if (!hidden.has(AuditType.PLZ_NICHT_ERKANNT)) {
return true;
}
}
}
}
return false;
}
);