Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Pham committed Dec 17, 2024
1 parent 38097b1 commit b416129
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
42 changes: 15 additions & 27 deletions graphql/mappers/contact-us.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { cachified } from 'cachified'
import { lruCache as cache, defaultTtl as ttl } from '../../lib/cache-utils'

interface GetSchContactUsV1 {
interface GetSchContactUsV2 {
data: {
schPageV1ByPath: {
item: {
schPageV1List: {
items: Array<{
_path: string
scPageNameEn: string
scPageNameFr: string
Expand Down Expand Up @@ -61,9 +61,8 @@ interface GetSchContactUsV1 {
scLinkTextAssistiveFr?: string
scDestinationURLEn?: string
scDestinationURLFr?: string
schBetaPopUp?: boolean
}>
}
}>
}
}
}
Expand All @@ -73,11 +72,10 @@ const getCachedContent = () => {
key: `content-contact-landing-page`,
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchContactUsV1`,
)
const targetUri = `${process.env.AEM_GRAPHQL_ENDPOINT}getSchContactUsV2%3BfolderName=${encodeURIComponent(process.env.AEM_GRAPHQL_FOLDER ?? '')}`
const response = await fetch(targetUri)
if (!response.ok) return null
return (await response.json()) as GetSchContactUsV1
return (await response.json()) as GetSchContactUsV2
},
ttl,
})
Expand All @@ -104,16 +102,16 @@ export async function getContactUsContent() {
const mappedSecurity = {
en: {
breadcrumb:
response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map(
response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map(
(level) => {
return {
link: level.scPageNameEn,
text: level.scTitleEn,
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameEn,
heading: response?.data.schPageV1ByPath.item.scTitleEn,
pageName: response?.data.schPageV1List.items[0].scPageNameEn,
heading: response?.data.schPageV1List.items[0].scTitleEn,
subHeading: introFragment?.scContentEn?.json[0].content[0].value,
links: [
{
Expand All @@ -124,7 +122,6 @@ export async function getContactUsContent() {
linkDescription: cdcpContactFragment?.scDescriptionEn?.json
? cdcpContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: cdcpContactFragment?.schBetaPopUp,
},
{
linkId: eiContactFragment?.scId,
Expand All @@ -134,7 +131,6 @@ export async function getContactUsContent() {
linkDescription: eiContactFragment?.scDescriptionEn?.json
? eiContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: eiContactFragment?.schBetaPopUp,
},
{
linkId: cppContactFragment?.scId,
Expand All @@ -144,7 +140,6 @@ export async function getContactUsContent() {
linkDescription: cppContactFragment?.scDescriptionEn?.json
? cppContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: cppContactFragment?.schBetaPopUp,
},
{
linkId: oasContactFragment?.scId,
Expand All @@ -154,7 +149,6 @@ export async function getContactUsContent() {
linkDescription: oasContactFragment?.scDescriptionEn?.json
? oasContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: oasContactFragment?.schBetaPopUp,
},
{
linkId: sinContactFragment?.scId,
Expand All @@ -164,22 +158,21 @@ export async function getContactUsContent() {
linkDescription: sinContactFragment?.scDescriptionEn?.json
? sinContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: sinContactFragment?.schBetaPopUp,
},
],
},
fr: {
breadcrumb:
response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map(
response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map(
(level) => {
return {
link: level.scPageNameFr,
text: level.scTitleFr,
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameFr,
heading: response?.data.schPageV1ByPath.item.scTitleFr,
pageName: response?.data.schPageV1List.items[0].scPageNameFr,
heading: response?.data.schPageV1List.items[0].scTitleFr,
subHeading: introFragment?.scContentFr?.json[0].content[0].value,
links: [
{
Expand All @@ -190,7 +183,6 @@ export async function getContactUsContent() {
linkDescription: cdcpContactFragment?.scDescriptionFr?.json
? cdcpContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: cdcpContactFragment?.schBetaPopUp,
},
{
linkId: eiContactFragment?.scId,
Expand All @@ -200,7 +192,6 @@ export async function getContactUsContent() {
linkDescription: eiContactFragment?.scDescriptionFr?.json
? eiContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: eiContactFragment?.schBetaPopUp,
},
{
linkId: cppContactFragment?.scId,
Expand All @@ -210,7 +201,6 @@ export async function getContactUsContent() {
linkDescription: cppContactFragment?.scDescriptionFr?.json
? cppContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: cppContactFragment?.schBetaPopUp,
},
{
linkId: oasContactFragment?.scId,
Expand All @@ -220,7 +210,6 @@ export async function getContactUsContent() {
linkDescription: oasContactFragment?.scDescriptionFr?.json
? oasContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: oasContactFragment?.schBetaPopUp,
},
{
linkId: sinContactFragment?.scId,
Expand All @@ -230,17 +219,16 @@ export async function getContactUsContent() {
linkDescription: sinContactFragment?.scDescriptionFr?.json
? sinContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: sinContactFragment?.schBetaPopUp,
},
],
},
}
return mappedSecurity
}

const findFragmentByScId = (res: GetSchContactUsV1 | null, id: string) => {
const findFragmentByScId = (res: GetSchContactUsV2 | null, id: string) => {
return (
res?.data.schPageV1ByPath.item.scFragments.find(
res?.data.schPageV1List.items[0].scFragments.find(
({ scId }) => scId === id,
) ?? null
)
Expand Down
10 changes: 5 additions & 5 deletions graphql/mappers/decision-reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface GetSchDecisionReviewsV1 {
scDestinationURLEn: string
scDestinationURLFr: string
schBetaPopUp: boolean
schURLType: string
schURLType?: string
}>
}>
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
areaLabel: askFragment?.scFragments[0].scLinkTextAssistiveEn,
link: buildLink(
askFragment?.scFragments[0].schURLType,
askFragment?.scFragments[0].scDestinationURLEn,
askFragment?.scFragments[0].scDestinationURLEn ?? '',
),
betaPopUp: askFragment?.scFragments[0].schBetaPopUp,
},
Expand All @@ -108,7 +108,7 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
areaLabel: appealFragment?.scFragments[0].scLinkTextAssistiveEn,
link: buildLink(
appealFragment?.scFragments[0].schURLType,
appealFragment?.scFragments[0].scDestinationURLEn,
appealFragment?.scFragments[0].scDestinationURLEn ?? '',
),
betaPopUp: appealFragment?.scFragments[0].schBetaPopUp,
},
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
areaLabel: askFragment?.scFragments[0].scLinkTextAssistiveFr,
link: buildLink(
askFragment?.scFragments[0].schURLType,
askFragment?.scFragments[0].scDestinationURLFr,
askFragment?.scFragments[0].scDestinationURLFr ?? '',
),
betaPopUp: askFragment?.scFragments[0].schBetaPopUp,
},
Expand All @@ -151,7 +151,7 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
areaLabel: appealFragment?.scFragments[0].scLinkTextAssistiveFr,
link: buildLink(
appealFragment?.scFragments[0].schURLType,
appealFragment?.scFragments[0].scDestinationURLFr,
appealFragment?.scFragments[0].scDestinationURLFr ?? '',
),
betaPopUp: appealFragment?.scFragments[0].schBetaPopUp,
},
Expand Down
4 changes: 2 additions & 2 deletions graphql/mappers/security-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export async function getSecuritySettingsContent(): Promise<SecuritySettingsCont
text: securityQuestions?.scLinkTextEn,
link: buildLink(
securityQuestions?.schURLType,
securityQuestions?.scDestinationURLEn,
securityQuestions?.scDestinationURLEn ?? '',
),
},
subTitle: securityQuestions?.scDescriptionEn.json[0].content[0].value,
Expand Down Expand Up @@ -186,7 +186,7 @@ export async function getSecuritySettingsContent(): Promise<SecuritySettingsCont
text: securityQuestions?.scLinkTextFr,
link: buildLink(
securityQuestions?.schURLType,
securityQuestions?.scDestinationURLFr,
securityQuestions?.scDestinationURLFr ?? '',
),
},
subTitle: securityQuestions?.scDescriptionFr.json[0].content[0].value,
Expand Down

0 comments on commit b416129

Please sign in to comment.