Files
online-energieausweis/src/components/Verbrauchsausweis/audits/PlzNichtErkannt.ts
2024-03-18 11:45:05 +01:00

23 lines
763 B
TypeScript

import { GebaeudeAufnahmeClient } from "#components/Ausweis/types";
import { client } from "src/trpc";
import { memoize } from "src/lib/Memoization";
import { AuditType, hidden } from "../audits/hidden";
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
});