From 3064b40508e7f6b23eccf88188da0e6ca558c176 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 11 Sep 2023 16:36:40 +0300 Subject: [PATCH 1/3] Test new standard schema --- .../src/lib/ecosystem/airtable/index.js | 5 +- .../src/lib/ecosystem/airtable/processData.js | 74 +++++++-------- apps/charterafrica/src/lib/ecosystem/index.js | 1 - .../fields/ecosystem/socialMediaFields.js | 85 +++++++++++++++++ .../src/payload/globals/Ecosystem.js | 92 +------------------ 5 files changed, 124 insertions(+), 133 deletions(-) create mode 100644 apps/charterafrica/src/payload/fields/ecosystem/socialMediaFields.js diff --git a/apps/charterafrica/src/lib/ecosystem/airtable/index.js b/apps/charterafrica/src/lib/ecosystem/airtable/index.js index e93a6130f..293649cf6 100644 --- a/apps/charterafrica/src/lib/ecosystem/airtable/index.js +++ b/apps/charterafrica/src/lib/ecosystem/airtable/index.js @@ -68,15 +68,13 @@ async function data(config) { organisationTableId, contributorTableId, partnersTableId, - socialMediaTableId, }, } = config; const toolsData = await table(baseId, toolTableId); const contributorsData = await table(baseId, contributorTableId); const organisationsData = await table(baseId, organisationTableId); - const socialMediaData = await table(baseId, socialMediaTableId); const partnersData = await table(baseId, partnersTableId); - const tableData = { socialMediaData, partnersData }; + const tableData = { partnersData }; const tools = toolsData .map((item) => processTool(item, config, tableData)) .filter(Boolean); @@ -90,7 +88,6 @@ async function data(config) { tools, organisations, contributors, - socialMedia: socialMediaData, partners: partnersData, }; } diff --git a/apps/charterafrica/src/lib/ecosystem/airtable/processData.js b/apps/charterafrica/src/lib/ecosystem/airtable/processData.js index d947741de..12ca65d42 100644 --- a/apps/charterafrica/src/lib/ecosystem/airtable/processData.js +++ b/apps/charterafrica/src/lib/ecosystem/airtable/processData.js @@ -29,7 +29,7 @@ function getRepoLink(source = "github", slug = "") { function mapSupporterIdsToObjects(supporterIds, config, { partnersData }) { const { - schema: { partnerTableColumns }, + schema: { partnerTableColumns = {} }, } = config; const { name, url, logo } = partnerTableColumns; const mapped = supporterIds.map((id) => { @@ -47,27 +47,32 @@ function mapSupporterIdsToObjects(supporterIds, config, { partnersData }) { return mapped.filter(Boolean); } -function mapSocialMediaIdsToObjects(socialMedia, config, tableData) { - const { - schema: { socialMediaTableColumns }, - } = config; - const { name, url } = socialMediaTableColumns; - const { socialMediaData = [] } = tableData; - const mapped = socialMedia.map((id) => { - const { fields } = socialMediaData.find((item) => item.id === id) || {}; - - if (!fields) { +function mapSocialMediaColumnsToObjects(columns, data) { + const getData = (name) => { + const link = getValue(data, columns[name]); + if (!link) { return null; } return { - name: getValue(fields, name), - link: getValue(fields, url), + name, + link, }; - }); - return mapped.filter(Boolean); + }; + return [ + getData("twitter"), + getData("facebook"), + getData("youtube"), + getData("slack"), + getData("tiktok"), + getData("linkedIn"), + getData("instagram"), + getData("telegram"), + getData("discord"), + getData("whatsapp"), + ].filter(Boolean); } -export function processTool(item, config, { partnersData, socialMediaData }) { +export function processTool(item, config, { partnersData }) { const { schema: { toolTableColumns }, localized, @@ -107,17 +112,16 @@ export function processTool(item, config, { partnersData, socialMediaData }) { const partners = mapSupporterIdsToObjects( getValue(data, toolTableColumns.partners) || [], config, - { partnersData, socialMediaData }, + { partnersData }, ); const supporters = mapSupporterIdsToObjects( getValue(data, toolTableColumns.supporters) || [], config, - { partnersData, socialMediaData }, + { partnersData }, ); - const socialMedia = mapSocialMediaIdsToObjects( - getValue(data, toolTableColumns.socialMedia) || [], - config, - { partnersData, socialMediaData }, + const socialMedia = mapSocialMediaColumnsToObjects( + toolTableColumns.socialMediaColumns, + data, ); const source = getSourceType(getValue(data, toolTableColumns.source.url)); return { @@ -139,11 +143,7 @@ export function processTool(item, config, { partnersData, socialMediaData }) { }; } -export function processContributor( - item, - config, - { partnersData, socialMediaData }, -) { +export function processContributor(item, config) { const { schema: { contributorTableColumns }, localized, @@ -157,10 +157,9 @@ export function processContributor( } const locales = localized ? ["en", "fr", "pt"] : ["en"]; - const socialMedia = mapSocialMediaIdsToObjects( - getValue(data, contributorTableColumns.socialMedia) || [], - config, - { partnersData, socialMediaData }, + const socialMedia = mapSocialMediaColumnsToObjects( + contributorTableColumns.socialMediaColumns, + data, ); const foundDescription = locales.reduce((acc, curr) => { const val = getValue(data, contributorTableColumns.description[curr]); @@ -185,11 +184,7 @@ export function processContributor( }; } -export function processOrganisation( - item, - config, - { partnersData, socialMediaData }, -) { +export function processOrganisation(item, config, { partnersData }) { const { schema: { organisationTableColumns }, localized, @@ -230,10 +225,9 @@ export function processOrganisation( config, { partnersData }, ); - const socialMedia = mapSocialMediaIdsToObjects( - getValue(data, organisationTableColumns.socialMedia) || [], - config, - { socialMediaData }, + const socialMedia = mapSocialMediaColumnsToObjects( + organisationTableColumns.socialMediaColumns, + data, ); const source = getSourceType( getValue(data, organisationTableColumns.source.url), diff --git a/apps/charterafrica/src/lib/ecosystem/index.js b/apps/charterafrica/src/lib/ecosystem/index.js index ba1a0088b..fd325134e 100644 --- a/apps/charterafrica/src/lib/ecosystem/index.js +++ b/apps/charterafrica/src/lib/ecosystem/index.js @@ -18,7 +18,6 @@ function checkConfig(config) { "contributorTableId", "organisationTableId", "partnersTableId", - "socialMediaTableId", ]; const isPresent = (tableName) => config?.schema?.[tableName]; return requiredTables.every(isPresent); diff --git a/apps/charterafrica/src/payload/fields/ecosystem/socialMediaFields.js b/apps/charterafrica/src/payload/fields/ecosystem/socialMediaFields.js new file mode 100644 index 000000000..8231da851 --- /dev/null +++ b/apps/charterafrica/src/payload/fields/ecosystem/socialMediaFields.js @@ -0,0 +1,85 @@ +import airtableColumnSelect from "./airtableColumnSelect"; + +function socialMediaColumns({ tableField, schema }) { + return { + label: "Social Media", + type: "group", + name: "socialMediaColumns", + fields: [ + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "twitter", + label: "Twitter", + }, + }), + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "tiktok", + label: "Tiktok", + }, + }), + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "facebook", + label: "Facebook", + }, + }), + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "linkedIn", + label: "Linkedin", + }, + }), + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "instagram", + label: "Instagram", + }, + }), + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "youtube", + label: "Youtube", + }, + }), + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "telegram", + label: "Telegram", + }, + }), + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "discord", + label: "Discord", + }, + }), + airtableColumnSelect({ + schema, + tableField, + overrides: { + name: "whatsapp", + label: "Whatsapp", + }, + }), + ], + }; +} + +export default socialMediaColumns; diff --git a/apps/charterafrica/src/payload/globals/Ecosystem.js b/apps/charterafrica/src/payload/globals/Ecosystem.js index 29ffe5fe8..7e64e63b2 100644 --- a/apps/charterafrica/src/payload/globals/Ecosystem.js +++ b/apps/charterafrica/src/payload/globals/Ecosystem.js @@ -3,6 +3,7 @@ import airtableBaseSelect, { } from "../fields/ecosystem/airtableBaseSelect"; import airtableColumnSelect from "../fields/ecosystem/airtableColumnSelect"; import airtableTableSelect from "../fields/ecosystem/airtableTableSelect"; +import socialMediaColumns from "../fields/ecosystem/socialMediaFields"; import sourceField from "../fields/ecosystem/sourceField"; import { ECOSYSTEM_GLOBAL } from "../utils/collections"; @@ -246,18 +247,6 @@ const Ecosystem = { }, }, }), - airtableColumnSelect({ - schema, - tableField: "toolTableId", - overrides: { - name: "socialMedia", - label: { - en: "Social Media", - fr: "Réseaux sociaux", - pt: "Mídia social", - }, - }, - }), sourceField({ tableField: "toolTableId", schema }), airtableColumnSelect({ schema, @@ -307,6 +296,7 @@ const Ecosystem = { }, }, }), + socialMediaColumns({ schema, tableField: "toolTableId" }), ], }, ], @@ -431,17 +421,9 @@ const Ecosystem = { hideGutter: true, }, }, - airtableColumnSelect({ + socialMediaColumns({ schema, tableField: "contributorTableId", - overrides: { - name: "socialMedia", - label: { - en: "Social Media", - fr: "Réseaux sociaux", - pt: "Mídia social", - }, - }, }), sourceField({ tableField: "contributorTableId", schema }), ], @@ -579,17 +561,9 @@ const Ecosystem = { }, }, }), - airtableColumnSelect({ + socialMediaColumns({ schema, tableField: "organisationTableId", - overrides: { - name: "socialMedia", - label: { - en: "Social Media", - fr: "Réseaux sociaux", - pt: "Mídia social", - }, - }, }), airtableColumnSelect({ schema, @@ -702,64 +676,6 @@ const Ecosystem = { }, ], }, - { - type: "collapsible", - label: { - en: "Social Media", - fr: "Réseaux sociaux", - pt: "Mídia social", - }, - admin: { - initCollapsed: true, - }, - fields: [ - airtableTableSelect({ - schema, - name: "socialMediaTableId", - label: { - en: "Table Name", - fr: "Nom du tableau", - pt: "Nome da tabela", - }, - }), - { - type: "group", - name: "socialMediaTableColumns", - label: { - en: "Columns", - fr: "Colonnes", - pt: "Colunas", - }, - admin: { - hideGutter: true, - }, - fields: [ - airtableColumnSelect({ - schema, - tableField: "socialMediaTableId", - overrides: { - name: "name", - label: { - en: "Name", - fr: "Nom", - pt: "Nome", - }, - }, - }), - airtableColumnSelect({ - schema, - tableField: "socialMediaTableId", - overrides: { - name: "url", - label: { - en: "URL", - }, - }, - }), - ], - }, - ], - }, ], }, ], From a141ecba24b4be540004e2234e08e8f4a089085e Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Tue, 12 Sep 2023 11:07:55 +0300 Subject: [PATCH 2/3] Implement feedback --- .../src/lib/ecosystem/airtable/processData.js | 15 +++------------ .../payload/fields/ecosystem/socialMediaFields.js | 3 +++ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/apps/charterafrica/src/lib/ecosystem/airtable/processData.js b/apps/charterafrica/src/lib/ecosystem/airtable/processData.js index 12ca65d42..fd78b2de3 100644 --- a/apps/charterafrica/src/lib/ecosystem/airtable/processData.js +++ b/apps/charterafrica/src/lib/ecosystem/airtable/processData.js @@ -58,18 +58,9 @@ function mapSocialMediaColumnsToObjects(columns, data) { link, }; }; - return [ - getData("twitter"), - getData("facebook"), - getData("youtube"), - getData("slack"), - getData("tiktok"), - getData("linkedIn"), - getData("instagram"), - getData("telegram"), - getData("discord"), - getData("whatsapp"), - ].filter(Boolean); + const SUPPORTED_SOCIAL_MEDIA = + "twitter,facebook,youtube,slack,tiktok,linkedIn,instagram,telegram,discord,whatsapp"; + return SUPPORTED_SOCIAL_MEDIA.split(",").map(getData).filter(Boolean); } export function processTool(item, config, { partnersData }) { diff --git a/apps/charterafrica/src/payload/fields/ecosystem/socialMediaFields.js b/apps/charterafrica/src/payload/fields/ecosystem/socialMediaFields.js index 8231da851..11cda27ac 100644 --- a/apps/charterafrica/src/payload/fields/ecosystem/socialMediaFields.js +++ b/apps/charterafrica/src/payload/fields/ecosystem/socialMediaFields.js @@ -79,6 +79,9 @@ function socialMediaColumns({ tableField, schema }) { }, }), ], + admin: { + hideGutter: true, + }, }; } From 4ac14dca771d6db752d4b811ccf5636da75f8ee9 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Tue, 12 Sep 2023 11:34:14 +0300 Subject: [PATCH 3/3] Remove unused files --- .../src/lib/ecosystem/airtable.old.js | 347 ------------------ .../src/lib/ecosystem/ecosystem.old.js | 118 ------ 2 files changed, 465 deletions(-) delete mode 100644 apps/charterafrica/src/lib/ecosystem/airtable.old.js delete mode 100644 apps/charterafrica/src/lib/ecosystem/ecosystem.old.js diff --git a/apps/charterafrica/src/lib/ecosystem/airtable.old.js b/apps/charterafrica/src/lib/ecosystem/airtable.old.js deleted file mode 100644 index c0227407f..000000000 --- a/apps/charterafrica/src/lib/ecosystem/airtable.old.js +++ /dev/null @@ -1,347 +0,0 @@ -import * as Sentry from "@sentry/nextjs"; -import Airtable from "airtable"; - -import api from "@/charterafrica/lib/payload"; -import { - CONTRIBUTORS_COLLECTION, - TOOL_COLLECTION, -} from "@/charterafrica/payload/utils/collections"; -import fetchJson, { FetchError } from "@/charterafrica/utils/fetchJson"; - -const airtable = new Airtable({ - apiKey: process.env.AIRTABLE_API_TOKEN, -}); - -function getter(data, key) { - return key ? data?.[key] : null; -} - -async function mapSupportersToFields(supporters, config, tableData) { - const { - schema: { partnerTableColumns }, - } = config; - const { name, url, logo } = partnerTableColumns; - const { partners } = tableData; - const mapped = supporters.map((id) => { - try { - const { fields } = partners.find((item) => id === item.id); - return { - name: getter(fields, name), - website: getter(fields, url), - logo: getter(fields, logo), - }; - } catch (error) { - Sentry.captureMessage(error.message); - return null; - } - }); - return mapped.filter(Boolean); -} - -async function getToolsPerAirtableId(ids) { - if (!ids || !ids?.length) { - return []; - } - const { docs } = await api.getCollection(TOOL_COLLECTION, { - where: { - airtableId: { - in: ids?.join(","), - }, - }, - }); - return docs.map(({ id }) => id); -} - -async function mapSocialMediaToFields(socialMedia, config, tableData) { - const { - schema: { socialMediaTableColumns }, - } = config; - const { name, url } = socialMediaTableColumns; - const { socialMedia: socialMediaData } = tableData; - const mapped = socialMedia.map((id) => { - try { - const { fields } = socialMediaData.find((item) => item.id === id); - return { - name: getter(fields, name), - website: getter(fields, url), - }; - } catch (error) { - Sentry.captureMessage(error.message); - return null; - } - }); - return mapped.filter(Boolean); -} - -export const getListFromAirtable = async ({ baseId, tableIdOrName }) => { - const base = airtable.base(baseId); - return base(tableIdOrName).select().all(); -}; - -export const processOrganisationFromAirTable = async ( - data, - config, - tableData, -) => { - try { - const { - schema: { organisationTableColumns }, - } = config; - const description = { - en: getter(data, organisationTableColumns.description.en), - pt: getter(data, organisationTableColumns.description.pt), - fr: getter(data, organisationTableColumns.description.fr), - }; - const partners = await mapSupportersToFields( - getter(data, organisationTableColumns.partners) || [], - config, - tableData, - ); - const supporters = await mapSupportersToFields( - getter(data, organisationTableColumns.supporters) || [], - config, - tableData, - ); - const socialMedia = await mapSocialMediaToFields( - getter(data, organisationTableColumns.socialMedia) || [], - config, - tableData, - ); - const tools = await getToolsPerAirtableId( - getter(data, organisationTableColumns.tools), - ); - const commonData = { - airtableId: data.id, - avatarUrl: getter(data, organisationTableColumns.avatarUrl)?.[0]?.url, - externalId: getter(data, organisationTableColumns.slug), - type: getter(data, organisationTableColumns.type), - repoLink: getter(data, organisationTableColumns.source.url), - supporters, - partners, - socialMedia, - tools, - }; - if (!commonData.externalId) { - const message = `Missing external ID for ${data.id}`; - Sentry.captureMessage(message); - throw new FetchError(message, data, 500); - } - if (!tools.length) { - const message = `Organisation ${data.id} is not assigned to any tool and has been skipped`; - Sentry.captureMessage(message); - throw new FetchError(message, data, 500); - } - return { - en: { - ...commonData, - description: description.en, - }, - fr: { - ...commonData, - description: description.fr, - }, - pt: { - ...commonData, - description: description.pt, - }, - }; - } catch (error) { - Sentry.captureMessage(error.message); - return null; - } -}; - -export const processContributorFromAirtable = async ( - data, - config, - tableData, -) => { - try { - const { - schema: { contributorTableColumns }, - } = config; - const socialMedia = await mapSocialMediaToFields( - getter(data, contributorTableColumns.socialMedia) || [], - config, - tableData, - ); - const description = { - en: getter(data, contributorTableColumns.description.en), - pt: getter(data, contributorTableColumns.description.pt), - fr: getter(data, contributorTableColumns.description.fr), - }; - const defaultData = { - airtableId: data.id, - avatarUrl: getter(data, contributorTableColumns.avatarUrl)?.[0]?.url, - externalId: getter(data, contributorTableColumns.slug), - repoLink: `https://github.com/${getter( - data, - contributorTableColumns.slug, - )}`, - socialMedia, - }; - return { - en: { - ...defaultData, - description: description.en, - }, - fr: { - ...defaultData, - description: description.fr, - }, - pt: { - ...defaultData, - description: description.pt, - }, - }; - } catch (error) { - Sentry.captureMessage(error.message); - return null; - } -}; - -export const processToolFromAirtable = async (data, config, tableData) => { - try { - const { - schema: { toolTableColumns }, - } = config; - const theme = { - en: getter(data, toolTableColumns.theme.en)?.[0], - pt: getter(data, toolTableColumns.theme.pt)?.[0], - fr: getter(data, toolTableColumns.theme.fr)?.[0], - }; - const description = { - en: getter(data, toolTableColumns.description.en), - pt: getter(data, toolTableColumns.description.pt), - fr: getter(data, toolTableColumns.description.fr), - }; - const { docs: contrib } = await api.getCollection(CONTRIBUTORS_COLLECTION, { - where: { - airtableId: { - in: getter(data, toolTableColumns.contributors)?.join(","), - }, - }, - }); - const operatingCountries = getter( - data, - toolTableColumns.operatingCountries, - ); - const homeCountry = getter(data, toolTableColumns.homeCountry); - const partners = await mapSupportersToFields( - getter(data, toolTableColumns.partners) || [], - config, - tableData, - ); - const supporters = await mapSupportersToFields( - getter(data, toolTableColumns.supporters) || [], - config, - tableData, - ); - const socialMedia = await mapSocialMediaToFields( - getter(data, toolTableColumns.socialMedia) || [], - config, - tableData, - ); - const defaultData = { - airtableId: data.id, - avatarUrl: getter(data, toolTableColumns.avatarUrl)?.[0]?.url, - externalId: getter(data, toolTableColumns.slug) || " ", - repoLink: getter(data, toolTableColumns.source.url), - name: getter(data, toolTableColumns.name), - link: getter(data, toolTableColumns.url), - operatingCountries, - contributors: contrib.map(({ id }) => id), - supporters, - partners, - homeCountry, - socialMedia, - }; - - return { - en: { - ...defaultData, - description: description.en, - theme: theme.en, - }, - fr: { - ...defaultData, - description: description.fr, - theme: theme.fr, - }, - pt: { - ...defaultData, - description: description.pt, - theme: theme.pt, - }, - }; - } catch (error) { - Sentry.captureMessage(error.message); - return null; - } -}; - -const cache = {}; - -function getFromCache(key) { - const rawData = cache[key]; - if (rawData) { - const { lastUpdated, value } = rawData; - const fiveMinutesAgo = new Date(); - fiveMinutesAgo.setMinutes(fiveMinutesAgo.getMinutes() - 5); - if (fiveMinutesAgo < lastUpdated) { - return value; - } - } - return null; -} - -export async function schema(req) { - const { url } = req.query; - const headers = { - "Content-Type": "application/json", - Authorization: `Bearer ${process.env.AIRTABLE_API_TOKEN}`, - }; - const cached = getFromCache(url); - if (cached) { - return cached; - } - const value = fetchJson.get(`https://api.airtable.com/v0${url}`, { - headers, - }); - cache[url] = { value, lastUpdated: new Date() }; - return value; -} - -export async function getAirtableData(config) { - const { - baseId, - schema: { - toolTableId, - organisationTableId, - contributorTableId, - partnersTableId, - socialMediaTableId, - }, - } = config; - const tools = await getListFromAirtable({ - baseId, - tableIdOrName: toolTableId, - }); - const contributors = await getListFromAirtable({ - baseId, - tableIdOrName: contributorTableId, - }); - const organisations = await getListFromAirtable({ - baseId, - tableIdOrName: organisationTableId, - }); - const socialMedia = await getListFromAirtable({ - baseId, - tableIdOrName: socialMediaTableId, - }); - const partners = await getListFromAirtable({ - baseId, - tableIdOrName: partnersTableId, - }); - return { tools, organisations, contributors, socialMedia, partners }; -} diff --git a/apps/charterafrica/src/lib/ecosystem/ecosystem.old.js b/apps/charterafrica/src/lib/ecosystem/ecosystem.old.js deleted file mode 100644 index 47cbf4490..000000000 --- a/apps/charterafrica/src/lib/ecosystem/ecosystem.old.js +++ /dev/null @@ -1,118 +0,0 @@ -import * as Sentry from "@sentry/nextjs"; - -import api from "../payload"; - -import { - getAirtableData, - processToolFromAirtable, - processOrganisationFromAirTable, - processContributorFromAirtable, -} from "@/charterafrica/lib/ecosystem/airtable.old"; -import { createCollection } from "@/charterafrica/lib/ecosystem/payload"; -import { - ORGANIZATION_COLLECTION, - CONTRIBUTORS_COLLECTION, - TOOL_COLLECTION, - ECOSYSTEM_GLOBAL, -} from "@/charterafrica/payload/utils/collections"; - -const bulkMarkDeleted = async (collection, fromSource) => { - const dataIds = fromSource.map(({ id }) => id).join(","); - const { docs: toDelete } = await api.getCollection(collection, { - where: { - airtableId: { - not_in: dataIds, - }, - }, - }); - Promise.all( - toDelete.map(async ({ id }) => { - try { - await api.updateCollection(collection, id, { - deletedAt: new Date(), - }); - } catch (error) { - Sentry.captureMessage(error.message); - } - }), - ); -}; -const processTools = async (config, tableData) => { - const { tools: toolsFromAirtable } = tableData; - await bulkMarkDeleted(TOOL_COLLECTION, toolsFromAirtable); - const processedToolPromises = toolsFromAirtable.map(async (data) => { - const airtableData = await processToolFromAirtable( - { - ...data.fields, - id: data.id, - }, - config, - tableData, - ); - // Only get git data if not exist in database - return createCollection(TOOL_COLLECTION, airtableData, config); - }); - return Promise.allSettled(processedToolPromises); -}; - -const processOrganisations = async (config, tableData) => { - const { organisations: organisationsFromAirtable } = tableData; - await bulkMarkDeleted(ORGANIZATION_COLLECTION, organisationsFromAirtable); - const processedOrgPromises = organisationsFromAirtable.map(async (data) => { - const airtableData = await processOrganisationFromAirTable( - { - ...data.fields, - id: data.id, - }, - config, - tableData, - ); - // Only get git data if not exist in database - return createCollection(ORGANIZATION_COLLECTION, airtableData, config); - }); - return Promise.allSettled(processedOrgPromises); -}; - -const processContributors = async (config, tableData) => { - const { contributors: contributorsFromAirtTable } = tableData; - await bulkMarkDeleted(CONTRIBUTORS_COLLECTION, contributorsFromAirtTable); - const processedContributors = contributorsFromAirtTable.map(async (data) => { - const airtableData = await processContributorFromAirtable( - { - ...data.fields, - id: data.id, - }, - config, - tableData, - ); - // Only get git data if not exist in database - return createCollection(CONTRIBUTORS_COLLECTION, airtableData, config); - }); - return Promise.allSettled(processedContributors); -}; - -export const updateEcosystemContent = async (req, res) => { - // For all list in database query Github API. using ETAG - res.status(200).json({}); -}; - -const execute = async () => { - Sentry.captureEvent({ - message: `Update Ecosystem List process started at ${new Date().toString()}`, - level: "info", - }); - const config = await api.findGlobal(ECOSYSTEM_GLOBAL, {}); - const tableData = await getAirtableData(config); - await processContributors(config, tableData); - await processTools(config, tableData); - await processOrganisations(config, tableData); - Sentry.captureEvent({ - message: `Update Ecosystem List process completed ${new Date().toString()}`, - level: "info", - }); -}; - -export const updateEcosystemList = async () => { - execute(); - return { message: "PROCESS_STARTED" }; -};