UNPKG

kentico-cloud-delivery

Version:

Official Kentico Cloud Delivery SDK

61 lines 2.45 kB
import { TaxonomyGroup, TaxonomySystemAttributes, TaxonomyTerms } from '../models'; var TaxonomyMapper = /** @class */ (function () { function TaxonomyMapper() { } TaxonomyMapper.prototype.mapTaxonomy = function (taxonomySystem, taxonomyTerms) { if (!taxonomySystem) { throw Error("Cannot map taxonomy due to missing 'system' property"); } if (!taxonomyTerms) { throw Error("Cannot map taxonomy due to missing 'terms' property"); } if (!Array.isArray(taxonomyTerms)) { throw Error("Cannot map terms because no terms array was provided"); } var mappedSystemAttributes = new TaxonomySystemAttributes({ name: taxonomySystem.name, codename: taxonomySystem.codename, id: taxonomySystem.id, lastModified: taxonomySystem.last_modified }); var mappedTerms = this.mapTaxonomyTerms(taxonomyTerms); return new TaxonomyGroup(mappedSystemAttributes, mappedTerms); }; TaxonomyMapper.prototype.mapTaxonomies = function (taxonomies) { var _this = this; if (!taxonomies) { throw Error("Cannot map taxonomy due to missing 'taxonomies' property"); } if (!Array.isArray(taxonomies)) { throw Error("Cannot map taxonomies because the 'taxonomies' property is not an array "); } var mappedTaxonomies = []; taxonomies.forEach(function (taxonomy) { mappedTaxonomies.push(_this.mapTaxonomy(taxonomy.system, taxonomy.terms)); }); return mappedTaxonomies; }; /** * Recursively map array of taxonomy terms * @param termsArray Terms array to map */ TaxonomyMapper.prototype.mapTaxonomyTerms = function (termsArray) { var _this = this; if (termsArray.length === 0) { return []; } var mappedTermsArray = []; termsArray.forEach(function (terms) { var mappedTerms = new TaxonomyTerms({ codename: terms.codename, name: terms.name, terms: _this.mapTaxonomyTerms(terms.terms) }); mappedTermsArray.push(mappedTerms); }); return mappedTermsArray; }; return TaxonomyMapper; }()); export { TaxonomyMapper }; //# sourceMappingURL=taxonomy.mapper.js.map