UNPKG

@kontent-ai/management-sdk

Version:
106 lines 5.47 kB
import { LanguageVariantModels } from '../models'; import { LanguageVariantResponses } from '../responses'; import { BaseMapper } from './base-mapper'; import { elementsMapper } from './elements-mapper'; export class LanguageVariantMapper extends BaseMapper { mapUpsertLanguageVariantResponse(response) { const variant = this.mapLanguageVariant(response.data); return new LanguageVariantResponses.UpsertLanguageVariantResponse(super.mapResponseDebug(response), response.data, variant); } mapViewLanguageVariantResponse(response) { const variant = this.mapLanguageVariant(response.data); return new LanguageVariantResponses.ViewLanguageVariantResponse(super.mapResponseDebug(response), response.data, variant); } mapLanguageVariantsOfItemResponse(response) { const variants = response.data.map((m) => this.mapLanguageVariant(m)); return new LanguageVariantResponses.ListLanguageVariantsOfItemResponse(super.mapResponseDebug(response), response.data, { items: variants }); } mapLanguageVariantsByCollectionResponse(response) { const variants = response.data.variants.map((m) => this.mapLanguageVariant(m)); return new LanguageVariantResponses.ListLanguageVariantsByCollectionResponse(super.mapResponseDebug(response), response.data, { items: variants, pagination: super.mapPagination(response.data.pagination) }); } mapFilterItemsWithVariantsResponse(response) { return new LanguageVariantResponses.FilterItemsWithVariantsResponse(super.mapResponseDebug(response), response.data, { items: response.data.variants, pagination: super.mapPagination(response.data.pagination) }); } mapBulkGetItemsWithVariantsResponse(response) { return new LanguageVariantResponses.BulkGetItemsWithVariantsResponse(super.mapResponseDebug(response), response.data, { items: response.data.data, pagination: super.mapPagination(response.data.pagination) }); } mapLanguageVariantsBySpaceResponse(response) { const variants = response.data.variants.map((m) => this.mapLanguageVariant(m)); return new LanguageVariantResponses.ListLanguageVariantsBySpaceResponse(super.mapResponseDebug(response), response.data, { items: variants, pagination: super.mapPagination(response.data.pagination) }); } mapLanguageVariantsOfContentTypeResponse(response) { const variants = response.data.variants.map((m) => this.mapLanguageVariant(m)); return new LanguageVariantResponses.ListLanguageVariantsOfContentTypeResponse(super.mapResponseDebug(response), response.data, { items: variants, pagination: super.mapPagination(response.data.pagination) }); } mapLanguageVariantsOfContentTypeWithComponentsResponse(response) { const variants = response.data.variants.map((m) => this.mapLanguageVariantWithComponents(m)); return new LanguageVariantResponses.ListLanguageVariantsOfContentTypeWithComponentsResponse(super.mapResponseDebug(response), response.data, { items: variants, pagination: super.mapPagination(response.data.pagination) }); } mapLanguageVariantWithComponents(rawVariant) { return new LanguageVariantModels.ContentItemLanguageWithComponentsVariant({ rawElements: rawVariant.elements, elements: elementsMapper.mapElements(rawVariant.elements), item: super.mapReference(rawVariant.item), language: super.mapReference(rawVariant.language), lastModified: new Date(rawVariant.last_modified), dueDate: this.mapDueDate(rawVariant.due_date), schedule: this.mapSchedule(rawVariant.schedule), workflow: { workflowIdentifier: super.mapReference(rawVariant.workflow.workflow_identifier), stepIdentifier: super.mapReference(rawVariant.workflow.step_identifier) }, _raw: rawVariant }); } mapLanguageVariant(rawVariant) { return new LanguageVariantModels.ContentItemLanguageVariant({ elements: elementsMapper.mapElements(rawVariant.elements), item: super.mapReference(rawVariant.item), language: super.mapReference(rawVariant.language), lastModified: new Date(rawVariant.last_modified), dueDate: this.mapDueDate(rawVariant.due_date), schedule: this.mapSchedule(rawVariant.schedule), note: rawVariant.note, contributors: rawVariant.contributors, workflow: { workflowIdentifier: super.mapReference(rawVariant.workflow.workflow_identifier), stepIdentifier: super.mapReference(rawVariant.workflow.step_identifier) }, _raw: rawVariant }); } mapDueDate(dueDateRaw) { return dueDateRaw; } mapSchedule(scheduleRaw) { return { publishDisplayTimezone: scheduleRaw.publish_display_timezone, publishTime: scheduleRaw.publish_time, unpublishDisplayTimezone: scheduleRaw.unpublish_display_timezone, unpublishTime: scheduleRaw.unpublish_time }; } } export const languageVariantMapper = new LanguageVariantMapper(); //# sourceMappingURL=language-variant-mapper.js.map