kentico-cloud-delivery
Version:
Official Kentico Cloud Delivery SDK
63 lines • 2.52 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var models_1 = require("../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 models_1.TaxonomySystemAttributes({
name: taxonomySystem.name,
codename: taxonomySystem.codename,
id: taxonomySystem.id,
lastModified: taxonomySystem.last_modified
});
var mappedTerms = this.mapTaxonomyTerms(taxonomyTerms);
return new models_1.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 models_1.TaxonomyTerms({
codename: terms.codename,
name: terms.name,
terms: _this.mapTaxonomyTerms(terms.terms)
});
mappedTermsArray.push(mappedTerms);
});
return mappedTermsArray;
};
return TaxonomyMapper;
}());
exports.TaxonomyMapper = TaxonomyMapper;
//# sourceMappingURL=taxonomy.mapper.js.map
;