submission.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { element } from "./element.js";
  2. class submission {
  3. #name;
  4. #description;
  5. #thumbnail;
  6. #elements;
  7. constructor(name) {
  8. if (typeof(name) !== "string") {
  9. throw "Name must be an string.";
  10. }
  11. this.#name = name;
  12. this.#description = "";
  13. this.#thumbnail = "";
  14. this.clean();
  15. }
  16. get name() {
  17. return this.#name;
  18. }
  19. get description() {
  20. return this.#description;
  21. }
  22. set description(content) {
  23. if (typeof(content) !== "string") {
  24. throw "Description must be an string.";
  25. }
  26. this.#description = content;
  27. }
  28. get thumbnail() {
  29. return this.#thumbnail;
  30. }
  31. set thumbnail(content) {
  32. if (typeof(content) !== "string") {
  33. throw "Thumbnail must be an string.";
  34. }
  35. this.#thumbnail = content;
  36. }
  37. get names() {
  38. return Object.keys(this.#elements);
  39. }
  40. get elements() {
  41. return Object.values(this.#elements);
  42. }
  43. add(item) {
  44. if (!(item instanceof element)) {
  45. throw "Trying to add something which is not an element.";
  46. }
  47. if (item.name in this.#elements) {
  48. throw "Trying to add element which already exists in submission.";
  49. }
  50. this.#elements[item.name] = item;
  51. }
  52. get(name) {
  53. if (typeof(name) !== "string") {
  54. throw "Name must be an string.";
  55. }
  56. if (!(name in this.#elements)) {
  57. throw "Trying to get element which not exists.";
  58. }
  59. return this.#elements[name];
  60. }
  61. clean() {
  62. this.#elements = {};
  63. }
  64. }
  65. export { submission };