From 50c07460f4c08678153c883fe6fb2df8a3f0b1be Mon Sep 17 00:00:00 2001 From: yashin4112 Date: Thu, 7 May 2026 17:35:17 +0530 Subject: [PATCH] refactor: streamline locale mapping process in createContentfulMapper; moved locale backend call above mapper --- upload-api/src/services/contentful/index.ts | 41 +++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/upload-api/src/services/contentful/index.ts b/upload-api/src/services/contentful/index.ts index 6a36ab38..0f02c233 100644 --- a/upload-api/src/services/contentful/index.ts +++ b/upload-api/src/services/contentful/index.ts @@ -25,6 +25,27 @@ const createContentfulMapper = async ( const cleanLocalPath = localPath?.replace?.(/\/$/, ''); const fetchedLocales: [] = await extractLocale(cleanLocalPath); + const mapperConfig = { + method: 'post', + maxBodyLength: Infinity, + url: `${process.env.NODE_BACKEND_API}/v2/migration/localeMapper/${projectId}`, + headers: { + app_token, + 'Content-Type': 'application/json' + }, + data: { + locale: Array.from(fetchedLocales) + } + }; + + const mapRes = await axios.request(mapperConfig); + if (mapRes?.status == 200) { + logger.info('Legacy CMS', { + status: HTTP_CODES?.OK, + message: HTTP_TEXTS?.LOCALE_SAVED + }); + } + await extractContentTypes(cleanLocalPath, affix); const initialMapper = await createInitialMapper(cleanLocalPath, affix); // Must run after createInitialMapper: that step deletes contentfulMigrationData (contentfulSchema) and would remove taxonomy files written earlier. @@ -67,26 +88,6 @@ const createContentfulMapper = async ( }); } - const mapperConfig = { - method: 'post', - maxBodyLength: Infinity, - url: `${process.env.NODE_BACKEND_API}/v2/migration/localeMapper/${projectId}`, - headers: { - app_token, - 'Content-Type': 'application/json' - }, - data: { - locale: Array.from(fetchedLocales) - } - }; - - const mapRes = await axios.request(mapperConfig); - if (mapRes?.status == 200) { - logger.info('Legacy CMS', { - status: HTTP_CODES?.OK, - message: HTTP_TEXTS?.LOCALE_SAVED - }); - } } catch (err: any) { console.error('🚀 ~ createContentfulMapper ~ err:', err?.response?.data ?? err); logger.warn('Validation error:', {