UNPKG

kentico-cloud-delivery

Version:

Official Kentico Cloud Delivery SDK

120 lines 5.2 kB
import { ElementResponses, ItemResponses, Pagination, TaxonomyResponses, TypeResponses } from '../models'; import { ElementMapper } from './element.mapper'; import { ItemMapper } from './item.mapper'; import { TaxonomyMapper } from './taxonomy.mapper'; import { TypeMapper } from './type.mapper'; var ResponseMapper = /** @class */ (function () { function ResponseMapper(config, richTextHtmlParser) { this.config = config; this.richTextHtmlParser = richTextHtmlParser; this.typeMapper = new TypeMapper(); this.itemMapper = new ItemMapper(config, richTextHtmlParser); this.taxonomyMapper = new TaxonomyMapper(); this.elementMapper = new ElementMapper(); } /** * Gets response for getting a single type * @param response Response data */ ResponseMapper.prototype.mapSingleTypeResponse = function (response) { var cloudResponse = response.data; // map type var type = this.typeMapper.mapSingleType(cloudResponse); return new TypeResponses.DeliveryTypeResponse(type, this.mapResponseDebug(response)); }; /** * Gets resposne for getting multiple types * @param response Response data * @param options Options */ ResponseMapper.prototype.mapMultipleTypeResponse = function (response) { var cloudResponse = response.data; // map types var types = this.typeMapper.mapMultipleTypes(cloudResponse); // pagination var pagination = new Pagination({ skip: cloudResponse.pagination.skip, count: cloudResponse.pagination.count, limit: cloudResponse.pagination.limit, next_page: cloudResponse.pagination.next_page }); return new TypeResponses.DeliveryTypeListingResponse(types, pagination, this.mapResponseDebug(response)); }; /** * Gets response for getting single item * @param response Response data * @param queryConfig Query configuration */ ResponseMapper.prototype.mapSingleResponse = function (response, queryConfig) { var cloudResponse = response.data; // map item var item = this.itemMapper.mapSingleItem(cloudResponse, queryConfig); return new ItemResponses.DeliveryItemResponse(item, this.mapResponseDebug(response)); }; /** * Gets response for getting multiple items * @param response Response data * @param queryConfig Query configuration */ ResponseMapper.prototype.mapMultipleResponse = function (response, queryConfig) { var cloudResponse = response.data; // map items var items = this.itemMapper.mapMultipleItems(cloudResponse, queryConfig); // pagination var pagination = new Pagination({ skip: cloudResponse.pagination.skip, count: cloudResponse.pagination.count, limit: cloudResponse.pagination.limit, next_page: cloudResponse.pagination.next_page }); return new ItemResponses.DeliveryItemListingResponse(items, pagination, this.mapResponseDebug(response)); }; /** * Gets response for getting single taxonomy item * @param response Response data */ ResponseMapper.prototype.mapTaxonomyResponse = function (response) { var cloudResponse = response.data; // map taxonomy var taxonomy = this.taxonomyMapper.mapTaxonomy(cloudResponse.system, cloudResponse.terms); return new TaxonomyResponses.TaxonomyResponse(taxonomy, this.mapResponseDebug(response)); }; /** * Gets response for getting multiples taxonomies * @param response Response data */ ResponseMapper.prototype.mapTaxonomiesResponse = function (response) { var cloudResponse = response.data; // map taxonomies var taxonomies = this.taxonomyMapper.mapTaxonomies(cloudResponse.taxonomies); // pagination var pagination = new Pagination({ skip: cloudResponse.pagination.skip, count: cloudResponse.pagination.count, limit: cloudResponse.pagination.limit, next_page: cloudResponse.pagination.next_page }); return new TaxonomyResponses.TaxonomiesResponse(taxonomies, pagination, this.mapResponseDebug(response)); }; /** * Gets response for getting single content type element * @param response Response data */ ResponseMapper.prototype.mapElementResponse = function (response) { var cloudResponse = response.data; // map element var element = this.elementMapper.mapElement(cloudResponse); return new ElementResponses.ElementResponse(element, this.mapResponseDebug(response)); }; ResponseMapper.prototype.mapResponseDebug = function (response) { if (!response) { throw Error("Cannot map 'debug' model from the response"); } return { response: response.response }; }; return ResponseMapper; }()); export { ResponseMapper }; //# sourceMappingURL=response.mapper.js.map