Skip to content

Commit

Permalink
fix: Website is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Jul 30, 2024
1 parent ce26114 commit f295572
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/pages/api/municipalities-data.csv.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from "fs";

import { csvFormat } from "d3";
import { mapValues } from "lodash";
import { NextApiHandler } from "next";
Expand All @@ -8,7 +10,7 @@ import buildEnv from "src/env/build";
const MunicipalityInfo = z
.object({
netzbetreiber: z.string(),
webseite: z.string(),
webseite: z.string().optional(),
gemeindeNummer: z.string().transform(Number),
gemeindeName: z.string(),
postleitzahl: z.string(),
Expand Down Expand Up @@ -128,12 +130,12 @@ WHERE {
},
});

const data = (await resp.json()) as unknown as SparqlResponse;
const json = (await resp.json()) as unknown as SparqlResponse;

const bindings = data.results.bindings;
return z
.array(MunicipalityInfo)
.parse(bindings.map((mv) => mapValues(mv, (x) => x.value)));
const bindings = json.results.bindings;
const data = bindings.map((mv) => mapValues(mv, (x) => x.value));
fs.writeFileSync("/tmp/data.json", JSON.stringify(data, null, 2));
return z.array(MunicipalityInfo).parse(data);
};

const handler: NextApiHandler = async (req, res) => {
Expand Down

0 comments on commit f295572

Please sign in to comment.