@goteborgco/open-api-js-client
Version:
Official JavaScript client for the Göteborg & Co GraphQL API
62 lines (61 loc) • 1.53 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaxonomyTerm = void 0;
/**
* Represents a single term within a taxonomy
*/
class TaxonomyTerm {
constructor(data) {
this.children = [];
this.id = data.id;
this.name = data.name;
this.count = data.count;
this.description = data.description;
this.parent = data.parent;
this.children = data.children?.map((child) => new TaxonomyTerm(child)) || [];
}
/**
* Check if this term has a parent
*/
hasParent() {
return this.parent !== undefined && this.parent !== null;
}
/**
* Get the parent ID if it exists
*/
getParentId() {
return this.parent;
}
/**
* Check if this term has children
*/
hasChildren() {
return this.children.length > 0;
}
/**
* Get all children of this term
*/
getChildren() {
return [...this.children];
}
/**
* Get the number of direct children
*/
getChildCount() {
return this.children.length;
}
/**
* Get all descendant terms (children, grandchildren, etc.)
*/
getAllDescendants() {
const descendants = [];
const stack = [...this.children];
while (stack.length > 0) {
const current = stack.pop();
descendants.push(current);
stack.push(...current.children);
}
return descendants;
}
}
exports.TaxonomyTerm = TaxonomyTerm;