Skip to content

Commit 3fa7824

Browse files
committed
feat(iab): reverse iab lookup from curration source
1 parent 1e933ba commit 3fa7824

File tree

5 files changed

+1444
-235
lines changed

5 files changed

+1444
-235
lines changed

clients/web/src/common/api/queries/get-syndicated-article.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { gql } from 'common/utilities/gql/gql'
22
import { requestGQL } from 'common/utilities/request/request'
3+
import { IABLookup } from 'common/iab'
34

45
const getSyndicatedArticleQuery = gql`
56
query GetSyndicatedArticle($slug: String!, $count: Int) {
@@ -80,5 +81,18 @@ export async function getSyndicatedArticle(slug) {
8081
variables
8182
})
8283
.then((response) => response?.data?.syndicatedArticleBySlug)
84+
.then(reverseLookupIAB)
8385
.catch((error) => console.error(error))
8486
}
87+
88+
function reverseLookupIAB(syndicatedArticleBySlug) {
89+
const { iabSubCategory, iabTopCategory } = syndicatedArticleBySlug
90+
const iabSubCategoryId = findKeyByLabel(iabSubCategory.trim())
91+
const iabTopCategoryId = findKeyByLabel(iabTopCategory.trim())
92+
return { ...syndicatedArticleBySlug, iabSubCategoryId, iabTopCategoryId }
93+
}
94+
95+
function findKeyByLabel(labelToFind) {
96+
const entry = IABLookup.find((item) => item.formatted === labelToFind)
97+
return entry ? entry.id : null
98+
}

0 commit comments

Comments
 (0)