mongoose-management
Version:
Mongoose schemas management tool
53 lines (52 loc) • 1.56 kB
JavaScript
;
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 group_1 = __importDefault(require("./group"));
const sort_1 = require("../helper/sort");
class GroupsDataset extends abstract_1.default {
constructor(data, pathProject) {
super(undefined);
this.pathProject = pathProject;
this.groups = data.groups.map((g) => new group_1.default(g, this));
}
setReference() {
this.groups.forEach((group) => group.setReference());
}
getGroups() {
return this.groups;
}
getGroup(path) {
const groups = this.groups.filter((g) => g.getPath() === path);
return groups.length === 1 ? groups[0] : undefined;
}
addGroup(group) {
this.groups.push(group);
this.sortGroups();
group.setReference();
return group;
}
removeGroup(group) {
this.groups = this.groups.filter((g) => g !== group);
}
sortGroups() {
this.groups.sort(sort_1.sortByPath);
}
getName() {
throw new Error('Groups has no name');
}
remove() {
throw new Error('Groups can not be removed');
}
getPathProject() {
return this.pathProject;
}
getObject() {
return {
groups: this.groups.map((g) => g.getObject()),
};
}
}
exports.default = GroupsDataset;