UNPKG

kentico-cloud-delivery

Version:

Official Kentico Cloud Delivery SDK

112 lines 5.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var mappers_1 = require("../mappers"); var models_1 = require("../models"); var MappingService = /** @class */ (function () { function MappingService(config, richTextHtmlParser) { this.config = config; this.richTextHtmlParser = richTextHtmlParser; this.typeMapper = new mappers_1.TypeMapper(); this.itemMapper = new mappers_1.ItemMapper(config, richTextHtmlParser); this.taxonomyMapper = new mappers_1.TaxonomyMapper(); this.genericElementMapper = new mappers_1.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 models_1.Pagination({ skip: response.data.pagination.skip, count: response.data.pagination.count, limit: response.data.pagination.limit, nextPage: response.data.pagination.next_page }); return new models_1.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 models_1.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 models_1.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 models_1.Pagination({ skip: response.data.pagination.skip, count: response.data.pagination.count, limit: response.data.pagination.limit, nextPage: response.data.pagination.next_page }); return new models_1.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 models_1.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 models_1.Pagination({ skip: response.data.pagination.skip, count: response.data.pagination.count, limit: response.data.pagination.limit, nextPage: response.data.pagination.next_page }); return new models_1.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 models_1.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; }()); exports.MappingService = MappingService; //# sourceMappingURL=mapping.service.js.map