| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { element } from "./element.js";
- import { submission } from "./submission.js";
- class database {
- #submissions;
- constructor() {
- this.clean();
- }
- search(input) {
- const phrase = input.trim();
- const found = [];
-
- this.submissions.forEach(name => {
- const current = this.#submissions[name];
- if (name.search(phrase) !== -1) {
- found.push(current);
- }
- current.elemenets.forEach(name => {
- if (name.search(phrase) !== -1) {
- found.push(current.get(name));
- }
- });
- });
- return found;
- }
-
- clean() {
- this.#submissions = {};
- }
- add(container) {
- if (!(container instanceof submission)) {
- throw "Trying to add something which is not an submission.";
- }
-
- if (container.name in this.#submissions) {
- throw "Trying to add submission which already exists.";
- }
- this.#submissions[container.name] = container;
- }
- get submissions() {
- return Object.keys(this.#submissions);
- }
- get(name) {
- if (typeof(name) !== "string") {
- throw "Submission name must be an string.";
- }
- if (!(name in this.#submissions)) {
- throw "Trying to get submission which not exists.";
- }
- return this.#submissions[name];
- }
- }
- export { database };
|