@kontent-ai/management-sdk
Version:
Official Kontent.ai management SDK
43 lines • 2.17 kB
JavaScript
import { ContentTypeModels } from '../models';
import { ContentTypeResponses } from '../responses';
import { BaseMapper } from './base-mapper';
import { elementsMapper } from './elements-mapper';
export class ContentTypeMapper extends BaseMapper {
mapListingResponse(response) {
return new ContentTypeResponses.ContentTypeListResponse(super.mapResponseDebug(response), response.data, {
items: response.data.types.map(m => this.mapContentType(m)),
pagination: super.mapPagination(response.data.pagination)
});
}
mapViewContentTypeResponse(response) {
return new ContentTypeResponses.ViewContentTypeResponse(super.mapResponseDebug(response), response.data, this.mapContentType(response.data));
}
mapModifyContentTypeResponse(response) {
return new ContentTypeResponses.ModifyContentTypeResponse(super.mapResponseDebug(response), response.data, this.mapContentType(response.data));
}
mapAddContentTypeResponse(response) {
return new ContentTypeResponses.AddContentTypeResponse(super.mapResponseDebug(response), response.data, this.mapContentType(response.data));
}
mapContentType(rawContentType) {
return new ContentTypeModels.ContentType({
codename: rawContentType.codename,
id: rawContentType.id,
name: rawContentType.name,
elements: elementsMapper.mapTypeElements(rawContentType.elements),
lastModified: new Date(rawContentType.last_modified),
externalId: rawContentType.external_id,
contentGroups: rawContentType.content_groups ? rawContentType.content_groups.map(m => this.mapContentTypeGroup(m)) : undefined,
_raw: rawContentType
});
}
mapContentTypeGroup(rawContentTypeGroup) {
return new ContentTypeModels.ContentTypeGroup({
name: rawContentTypeGroup.name,
codename: rawContentTypeGroup.codename,
externalId: rawContentTypeGroup.external_id,
id: rawContentTypeGroup.id
});
}
}
export const contentTypeMapper = new ContentTypeMapper();
//# sourceMappingURL=content-type-mapper.js.map