From f96f1613b69d530252e04d7700f1aa96b4c9c56e Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Thu, 27 Jun 2024 11:55:33 +0300 Subject: [PATCH] Ensure key fields exist --- .../src/lib/ecosystem/airtable/processData.js | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/apps/charterafrica/src/lib/ecosystem/airtable/processData.js b/apps/charterafrica/src/lib/ecosystem/airtable/processData.js index c8736cf1a..3637a75ab 100644 --- a/apps/charterafrica/src/lib/ecosystem/airtable/processData.js +++ b/apps/charterafrica/src/lib/ecosystem/airtable/processData.js @@ -20,6 +20,16 @@ function getSourceType(link) { return "github"; } +function checkFields(obj) { + const emptyFields = Object.keys(obj) + .map((field) => (!obj[field] ? field : null)) + .filter(Boolean); + if (emptyFields.length > 0) { + return `The following fields are missing ${emptyFields.join(", ")}`; + } + return null; +} + function getRepoLink(source = "github", slug = "") { if (source === "github" && slug) { return `https://github.com/${slug}`; @@ -70,8 +80,8 @@ export function processTool(item, config, { partnersData }) { } = config; const data = { ...item.fields, id: item.id }; const externalId = getValue(data, toolTableColumns.slug)?.trim(); - const toolName = getValue(data, toolTableColumns.name)?.trim(); - if (!toolName) { + const name = getValue(data, toolTableColumns.name)?.trim(); + if (!name) { const message = `Missing name for Tool ${data.id}. Skipping`; Sentry.captureMessage(message); return null; @@ -116,12 +126,28 @@ export function processTool(item, config, { partnersData }) { data, ); const source = getSourceType(getValue(data, toolTableColumns.source.url)); + const avatarUrl = + getValue(data, toolTableColumns.avatarUrl)?.[0]?.url ?? null; + const fieldsToCheck = { + avatarUrl, + name, + description, + operatingCountries, + theme, + }; + const missingFields = checkFields(fieldsToCheck); + if (missingFields) { + const message = `Tool ${name}: ${missingFields}`; + Sentry.captureMessage(message); + return null; + } + return { airtableId: data.id, - avatarUrl: getValue(data, toolTableColumns.avatarUrl)?.[0]?.url ?? null, + avatarUrl, externalId, repoLink: getValue(data, toolTableColumns.source.url), - name: getValue(data, toolTableColumns.name), + name, link: getValue(data, toolTableColumns.url), operatingCountries, contributors: getValue(data, toolTableColumns.contributors),