UNPKG

mongoose-management

Version:
57 lines (56 loc) 1.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const abstract_1 = __importDefault(require("./abstract")); const collection_1 = __importDefault(require("./collection")); const sort_1 = require("../helper/sort"); class GroupDataset extends abstract_1.default { constructor(group, groups) { super(groups); this.path = group.path; this.collections = group.collections.map((c) => new collection_1.default(c, this)); } setReference() { this.collections.forEach((collection) => collection.setReference()); } getPath() { return this.path; } setPath(path) { this.path = path; } getCollections() { return this.collections; } getCollection(name) { const collections = this.collections.filter((c) => c.getName() === name); return collections.length === 1 ? collections[0] : undefined; } addCollection(collection) { this.collections.push(collection); this.sortCollections(); collection.setReference(); return collection; } removeCollection(collection) { this.collections = this.collections.filter((c) => c !== collection); } sortCollections() { this.collections.sort(sort_1.sortByName); } getName() { return this.getPath(); } remove() { this.parent.removeGroup(this); } getObject() { return { path: this.path, collections: this.collections.map((c) => c.getObject()), }; } } exports.default = GroupDataset;