project.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { submission } from "./submission.js";
  2. class project {
  3. #name;
  4. #description;
  5. #submissions;
  6. constructor(name) {
  7. this.#name = name;
  8. this.#description = "";
  9. this.clean();
  10. }
  11. get name() {
  12. return this.#name;
  13. }
  14. get description() {
  15. return this.#description;
  16. }
  17. set description(content) {
  18. if (typeof(content) !== "string") {
  19. throw "Description must be an string.";
  20. }
  21. this.#description = content;
  22. }
  23. get submissions() {
  24. return Object.keys(this.#submissions);
  25. }
  26. get(name) {
  27. if (typeof(name) !== "string") {
  28. throw "Name of submission must be an string.";
  29. }
  30. return this.#submissions[name];
  31. }
  32. add(content) {
  33. if (!(content instanceof submission)) {
  34. throw "New submission must be instance of submission class.";
  35. }
  36. if (content.name in this.#submissions) {
  37. throw "Trying to add submission which already exists.";
  38. }
  39. this.#submissions[content.name] = content;
  40. }
  41. clean() {
  42. this.#submissions = {};
  43. }
  44. }
  45. export { project };