import { generateReportFromData, batchedQuery } from "../helpers.js"; import { PREFIXES } from "./utils"; export default { cronPattern: "0 00 23 * * *", name: "organizations", execute: async () => { const reportData = { title: "organisations in database", description: "List of the Organisations in the database", filePrefix: "exports/organizations", }; console.log("Generating organizations report"); const queryString = ` ${PREFIXES} PREFIX org: PREFIX adms: PREFIX generiek: PREFIX skos: SELECT DISTINCT ?bestuur ?label ?classification ?typeEredienst ?provincie ?status WHERE { ?bestuur a org:Organization . OPTIONAL { ?bestuur ?site. ?site ?address. ?address ?provincie } OPTIONAL {?bestuur ?typeEredienst.} OPTIONAL {?bestuur skos:prefLabel ?label} OPTIONAL { ?bestuur ?org_classification . ?org_classification skos:prefLabel ?classification } OPTIONAL { ?bestuur ?org_status. ?org_status skos:prefLabel ?status. } } `; const queryResponse = await batchedQuery(queryString); const data = queryResponse.results.bindings.map((row) => ({ "bestuur": getSafeValue(row, "bestuur"), "label": getSafeValue(row, "label"), "classification": getSafeValue(row, "classification"), "typeEredienst": getSafeValue(row, "typeEredienst"), "provincie": getSafeValue(row, "provincie"), "status": getSafeValue(row, "status"), })); await generateReportFromData( data, [ "bestuur", "label", "classification", "typeEredienst", "provincie", "status", ], reportData, ); }, }; function getSafeValue(entry, property) { return entry[property] ? wrapInQuote(entry[property].value) : null; } // Some values might contain commas; wrapping them in escapes quotes doesn't disrupt the columns. function wrapInQuote(value) { return `\"${value}\"`; }