Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
feat: uses different endpoint for fetching language variants to ensur…
Browse files Browse the repository at this point in the history
…e all variants are loaded
  • Loading branch information
Enngage committed Dec 17, 2020
1 parent b4fe8f0 commit 6bdda7d
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions src/export/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ export class ExportService {

const contentTypes = await this.exportContentTypesAsync({ processItem: exportItems.contentType });
const projectValidation = await this.exportProjectValidationAsync();
const contentItems = exportItems.contentItem || exportItems.languageVariant ? await this.exportContentItemsAsync() : []

const data: IExportData = {
contentTypes: exportItems.contentType ? contentTypes : [],
contentTypeSnippets: exportItems.contentTypeSnippet ? await this.exportContentTypeSnippetsAsync() : [],
taxonomies: exportItems.taxonomy ? await this.exportTaxonomiesAsync() : [],
contentItems: exportItems.contentItem ? await this.exportContentItemsAsync() : [],
languageVariants: exportItems.languageVariant
? await this.exportLanguageVariantsAsync(contentTypes.map((m) => m.id))
? await this.exportLanguageVariantsAsync(contentItems.map((m) => m.id))
: [],
assets: exportItems.asset ? await this.exportAssetsAsync() : [],
languages: exportItems.language ? await this.exportLanguagesAsync() : [],
Expand Down Expand Up @@ -161,36 +162,21 @@ export class ExportService {
}

public async exportLanguageVariantsAsync(
typeIds: string[]
contentItemIds: string[]
): Promise<LanguageVariantContracts.ILanguageVariantModelContract[]> {
const languageVariants: LanguageVariantContracts.ILanguageVariantModelWithComponentsContract[] = [];

for (const typeId of typeIds) {
await this.client
.listLanguageVariantsOfContentTypeWithComponents()
.byTypeId(typeId)
.withListQueryConfig({
responseFetched: (listResponse, token) => {
languageVariants.push(...listResponse.data.items.map((m) => m._raw));
listResponse.data.items.forEach((m) =>
this.processItem(m.item.id?.toString() ?? '-', 'languageVariant', m)
);
}
})
.toAllPromise();

await this.client
.listLanguageVariantsOfContentType()
.byTypeId(typeId)
.withListQueryConfig({
responseFetched: (listResponse, token) => {
languageVariants.push(...listResponse.data.items.map((m) => m._raw));
listResponse.data.items.forEach((m) =>
this.processItem(m.item.id?.toString() ?? '-', 'languageVariant', m)
);
}
})
.toAllPromise();
for (const contentItemId of contentItemIds) {
const response = await this.client
.listLanguageVariantsOfItem()
.byItemId(contentItemId)
.toPromise();


languageVariants.push(...response.data.items.map((m) => m._raw));
response.data.items.forEach((m) =>
this.processItem(m.item.id?.toString() ?? '-', 'languageVariant', m)
);
}

return languageVariants;
Expand Down

0 comments on commit 6bdda7d

Please sign in to comment.