diff --git a/api-error-handler.js b/api-error-handler.js index 93a6115..3cdd589 100644 --- a/api-error-handler.js +++ b/api-error-handler.js @@ -1,17 +1,17 @@ export const API_STATUS_CODES = { - STATUS_200:{ + OK:{ STATUS: "OK", CODE: 200 }, - STATUS_402:{ + ERROR_NO_DATA_WEGWIJS:{ STATUS: "no data has been found, check if kbo numer is correct or organisation has OVO number. Organisation without OVO number are not in wegwijs", - CODE: 402 + CODE: 500 }, - STATUS_403:{ + STATUS_NO_DATA_OP:{ STATUS: "no kbo number found in OP", - CODE: 403 + CODE: 500, }, - STATUS_500:{ + CUSTOM_SERVER_ERROR:{ STATUS: '', CODE: 500 } diff --git a/app.js b/app.js index e6b60df..f641cdd 100644 --- a/app.js +++ b/app.js @@ -26,7 +26,7 @@ app.post("/sync-kbo-data/:kboStructuredIdUuid", async function (req, res) { const AbbOrganizationInfo = await getAbbOrganizationInfo(kboStructuredIdUuid); if (!AbbOrganizationInfo?.kbo) { - return throwServerError(API_STATUS_CODES.STATUS_403, res); + return throwServerError(API_STATUS_CODES.STATUS_NO_DATA_OP, res); } const wegwijsUrl = `${WEGWIJS_API}?q=kboNumber:${AbbOrganizationInfo.kbo}&fields=${WEGWIJS_API_FIELDS}`; console.log("url: " + wegwijsUrl); @@ -35,7 +35,7 @@ app.post("/sync-kbo-data/:kboStructuredIdUuid", async function (req, res) { const data = await response.json(); if (!data.length) { - return throwServerError(API_STATUS_CODES.STATUS_402, res); + return throwServerError(API_STATUS_CODES.ERROR_NO_DATA_WEGWIJS, res); } // We got a match on the KBO, getting the associated OVO back const wegwijsInfo = data[0]; // Wegwijs should only have only one entry per KBO @@ -65,9 +65,9 @@ app.post("/sync-kbo-data/:kboStructuredIdUuid", async function (req, res) { await updateOvoNumberAndUri(ovoStructuredIdUri, wegwijsOvo); } - return throwServerError(API_STATUS_CODES.STATUS_200, res); // since we await, it should be 200 + return throwServerError(API_STATUS_CODES.OK, res); // since we await, it should be 200 } catch (e) { - return throwServerError(API_STATUS_CODES.STATUS_500, res, e); + return throwServerError(API_STATUS_CODES.CUSTOM_SERVER_ERROR, res, e); } }); @@ -121,20 +121,19 @@ function getKboFields(data) { //currently no commercial name available return { - changeTime: changeTime ?? "", - commercialName: "", - shortName: shortName ?? organisationName, - ovoNumber: ovoNumber ?? "", - kboNumber: kboNumber ?? "", - formalName: formalName ?? "", - startDate: startDate ?? "", + changeTime: changeTime, + shortName: shortName, + ovoNumber: ovoNumber, + kboNumber: kboNumber, + formalName: formalName, + startDate: startDate, activeState: activeState, - rechtsvorm: rechtsvorm ?? "", - email: email ?? "", - phone: phone ?? "", - website: website ?? "", - formattedAddress: formattedAddress ?? "", - adressComponent: adressComponent ?? "", + rechtsvorm: rechtsvorm, + email: email, + phone: phone, + website: website, + formattedAddress: formattedAddress, + adressComponent: adressComponent, }; } diff --git a/lib/queries.js b/lib/queries.js index 36232b8..d6e3ec1 100644 --- a/lib/queries.js +++ b/lib/queries.js @@ -338,24 +338,19 @@ export async function createNewKboOrg(kboOrg, kboId) { kboOrg.rechtsvorm )}`; } - if (kboOrg.shortName) { - updateStr += `; ${sparqlEscapeString( - kboOrg.shortName - )}`; - } if (kboOrg.startDate) { updateStr += `; ${sparqlEscapeString( kboOrg.startDate )}`; } if (kboOrg.formalName) { - updateStr += `; ${sparqlEscapeString( + updateStr += `; ${sparqlEscapeString( kboOrg.formalName )}`; } - if (kboOrg.commercialName) { - updateStr += `; ${sparqlEscapeString( - kboOrg.commercialName + if (kboOrg.shortName) { + updateStr += `; ${sparqlEscapeString( + kboOrg.shortName )}`; } if (kboOrg.changeTime) { @@ -545,14 +540,6 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) { )} `; } - if (newKboInfo.shortName) { - updateStr += ` - ; - ${sparqlEscapeString( - newKboInfo.shortName - )} - `; - } if (newKboInfo.startDate) { updateStr += ` ; @@ -561,21 +548,15 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) { )} `; } - if (newKboInfo.organisationName) { - updateStr += ` - ; - ${sparqlEscapeString( - newKboInfo.organisationName - )} - `; - } if (newKboInfo.formalName) { - updateStr += ` - ; - ${sparqlEscapeString( + updateStr += `; ${sparqlEscapeString( newKboInfo.formalName - )} - `; + )}`; + } + if (newKboInfo.shortName) { + updateStr += `; ${sparqlEscapeString( + newKboInfo.shortName + )}`; } if (newKboInfo.changeTime) { updateStr += `