Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cms): Most common page types are now directly fetched from cms #16320

Merged
merged 9 commits into from
Nov 5, 2024
66 changes: 46 additions & 20 deletions libs/cms/src/lib/cms.contentful.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { ContentfulRepository, localeMap } from './contentful.repository'
import { GetAlertBannerInput } from './dto/getAlertBanner.input'
import { AlertBanner, mapAlertBanner } from './models/alertBanner.model'
import { mapUrl, Url } from './models/url.model'
import { mapTellUsAStory, TellUsAStory } from './models/tellUsAStory.model'
import { GetSubpageHeaderInput } from './dto/getSubpageHeader.input'
import { mapSubpageHeader, SubpageHeader } from './models/subpageHeader.model'
import {
Expand Down Expand Up @@ -90,20 +89,41 @@ const errorHandler = (name: string) => {
}
}

const ArticleFields = [
// we want to exclude relatedArticles because it's a self-referencing
// relation and selecting related articles to a depth of 10 would make the
// response huge
'sys',
'fields.slug',
'fields.title',
'fields.shortTitle',
'fields.content',
'fields.subgroup',
'fields.group',
'fields.category',
'fields.subArticles',
].join(',')
const ArticleFields = (
[
// we want to exclude relatedArticles because it's a self-referencing
// relation and selecting related articles to a depth of 10 would make the
// response huge
'sys',
'fields.activeTranslations',
'fields.alertBanner',
'fields.category',
'fields.content',
'fields.contentStatus',
'fields.featuredImage',
'fields.group',
'fields.importance',
'fields.intro',
'fields.organization',
'fields.otherCategories',
'fields.otherGroups',
'fields.otherSubgroups',
'fields.processEntry',
'fields.processEntryButtonText',
'fields.relatedContent',
'fields.relatedOrganization',
'fields.responsibleParty',
'fields.shortTitle',
'fields.showTableOfContents',
'fields.signLanguageVideo',
'fields.slug',
'fields.stepper',
'fields.subArticles',
'fields.subgroup',
'fields.title',
'fields.userStories',
] as ('sys' | `fields.${keyof types.IArticle['fields']}`)[]
).join(',')

@Injectable()
export class CmsContentfulService {
Expand Down Expand Up @@ -378,8 +398,9 @@ export class CmsContentfulService {
): Promise<OrganizationPage> {
const params = {
['content_type']: 'organizationPage',
include: 10,
include: 5,
'fields.slug': slug,
limit: 1,
}

const result = await this.contentfulRepository
Expand All @@ -399,10 +420,11 @@ export class CmsContentfulService {
): Promise<OrganizationSubpage> {
const params = {
['content_type']: 'organizationSubpage',
include: 10,
include: 5,
'fields.slug': slug,
'fields.organizationPage.sys.contentType.sys.id': 'organizationPage',
'fields.organizationPage.fields.slug': organizationSlug,
limit: 1,
}
const result = await this.contentfulRepository
.getLocalizedEntries<types.IOrganizationSubpageFields>(lang, params)
Expand Down Expand Up @@ -467,6 +489,7 @@ export class CmsContentfulService {
const params = {
['content_type']: 'projectPage',
'fields.slug': slug,
limit: 1,
}

const result = await this.contentfulRepository
Expand All @@ -483,7 +506,8 @@ export class CmsContentfulService {
['content_type']: 'article',
'fields.slug': slug,
select: ArticleFields,
include: 10,
include: 5,
limit: 1,
}

const result = await this.contentfulRepository
Expand Down Expand Up @@ -542,8 +566,9 @@ export class CmsContentfulService {
async getNews(lang: string, slug: string): Promise<News | null> {
const params = {
['content_type']: 'news',
include: 10,
include: 5,
'fields.slug': slug,
limit: 1,
}

const result = await this.contentfulRepository
Expand Down Expand Up @@ -828,8 +853,9 @@ export class CmsContentfulService {
const params = {
['content_type']: 'frontpage',
'fields.pageIdentifier': pageIdentifier,
include: 10,
include: 5,
order: '-sys.createdAt',
limit: 1,
}

const result = await this.contentfulRepository
Expand Down
26 changes: 10 additions & 16 deletions libs/cms/src/lib/cms.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,18 @@ export class CmsResolver {
async getOrganizationPage(
@Args('input') input: GetOrganizationPageInput,
): Promise<OrganizationPage | null> {
return this.cmsElasticsearchService.getSingleDocumentTypeBySlug(
getElasticsearchIndex(input.lang),
{ type: 'webOrganizationPage', slug: input.slug },
)
return this.cmsContentfulService.getOrganizationPage(input.slug, input.lang)
}

@CacheControl(defaultCache)
@Query(() => OrganizationSubpage, { nullable: true })
async getOrganizationSubpage(
@Args('input') input: GetOrganizationSubpageInput,
): Promise<OrganizationSubpage | null> {
return this.cmsElasticsearchService.getSingleOrganizationSubpage(
getElasticsearchIndex(input.lang),
{ ...input },
return this.cmsContentfulService.getOrganizationSubpage(
input.organizationSlug,
input.slug,
input.lang,
)
}

Expand Down Expand Up @@ -422,11 +420,10 @@ export class CmsResolver {
async getSingleArticle(
@Args('input') { lang, slug }: GetSingleArticleInput,
): Promise<(Partial<Article> & { lang: Locale }) | null> {
const article: Article | null =
await this.cmsElasticsearchService.getSingleDocumentTypeBySlug<Article>(
getElasticsearchIndex(lang),
{ type: 'webArticle', slug },
)
const article: Article | null = await this.cmsContentfulService.getArticle(
slug,
lang,
)

if (!article) return null

Expand All @@ -452,10 +449,7 @@ export class CmsResolver {
getSingleNews(
@Args('input') { lang, slug }: GetSingleNewsInput,
): Promise<News | null> {
return this.cmsElasticsearchService.getSingleDocumentTypeBySlug<News>(
getElasticsearchIndex(lang),
{ type: 'webNews', slug },
)
return this.cmsContentfulService.getNews(lang, slug)
RunarVestmann marked this conversation as resolved.
Show resolved Hide resolved
}

@CacheControl(defaultCache)
Expand Down
Loading