UNPKG

kentico-cloud-delivery

Version:

Official Kentico Cloud Delivery SDK

110 lines 4.97 kB
import { GenericElementMapper, ItemMapper, TaxonomyMapper, TypeMapper } from '../mappers'; import { ElementResponses, ItemResponses, Pagination, TaxonomyResponses, TypeResponses, } from '../models'; var MappingService = /** @class */ (function () { function MappingService(config, richTextHtmlParser) { this.config = config; this.richTextHtmlParser = richTextHtmlParser; this.typeMapper = new TypeMapper(); this.itemMapper = new ItemMapper(config, richTextHtmlParser); this.taxonomyMapper = new TaxonomyMapper(); this.genericElementMapper = new GenericElementMapper(); } /** * Gets response for getting a single type * @param response Response data */ MappingService.prototype.listContentTypesResponse = function (response) { // map types var types = this.typeMapper.mapMultipleTypes(response.data); // pagination var pagination = new Pagination({ skip: response.data.pagination.skip, count: response.data.pagination.count, limit: response.data.pagination.limit, nextPage: response.data.pagination.next_page }); return new TypeResponses.ListContentTypesResponse(types, pagination, this.mapResponseDebug(response)); }; /** * Gets resposne for getting multiple types * @param response Response data * @param options Options */ MappingService.prototype.viewContentTypeResponse = function (response) { // map type var type = this.typeMapper.mapSingleType(response.data); return new TypeResponses.ViewContentTypeResponse(type, this.mapResponseDebug(response)); }; /** * Gets response for getting single item * @param response Response data * @param queryConfig Query configuration */ MappingService.prototype.viewContentItemResponse = function (response, queryConfig) { // map item var itemResult = this.itemMapper.mapSingleItem(response.data, queryConfig); return new ItemResponses.ViewContentItemResponse(itemResult.item, itemResult.processedItems, this.mapResponseDebug(response)); }; /** * Gets response for getting multiple items * @param response Response data * @param queryConfig Query configuration */ MappingService.prototype.listContentItemsResponse = function (response, queryConfig) { // map items var itemsResult = this.itemMapper.mapMultipleItems(response.data, queryConfig); // pagination var pagination = new Pagination({ skip: response.data.pagination.skip, count: response.data.pagination.count, limit: response.data.pagination.limit, nextPage: response.data.pagination.next_page }); return new ItemResponses.ListContentItemsResponse(itemsResult.items, pagination, itemsResult.processedItems, this.mapResponseDebug(response)); }; /** * Gets response for getting single taxonomy item * @param response Response data */ MappingService.prototype.viewTaxonomyGroupResponse = function (response) { // map taxonomy var taxonomy = this.taxonomyMapper.mapTaxonomy(response.data.system, response.data.terms); return new TaxonomyResponses.ViewTaxonomyGroupResponse(taxonomy, this.mapResponseDebug(response)); }; /** * Gets response for getting multiples taxonomies * @param response Response data */ MappingService.prototype.listTaxonomyGroupsResponse = function (response) { // map taxonomies var taxonomies = this.taxonomyMapper.mapTaxonomies(response.data.taxonomies); // pagination var pagination = new Pagination({ skip: response.data.pagination.skip, count: response.data.pagination.count, limit: response.data.pagination.limit, nextPage: response.data.pagination.next_page }); return new TaxonomyResponses.ListTaxonomyGroupsResponse(taxonomies, pagination, this.mapResponseDebug(response)); }; /** * Gets response for getting single content type element * @param response Response data */ MappingService.prototype.viewContentTypeElementResponse = function (response) { // map element var element = this.genericElementMapper.mapElement(response.data); return new ElementResponses.ViewContentTypeElementResponse(element, this.mapResponseDebug(response)); }; MappingService.prototype.mapResponseDebug = function (response) { if (!response) { throw Error("Cannot map 'debug' model from the response"); } return { response: response.response }; }; return MappingService; }()); export { MappingService }; //# sourceMappingURL=mapping.service.js.map