project.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 names() {
  24. return Object.keys(this.#submissions);
  25. }
  26. get submissions() {
  27. return Object.values(this.#submissions);
  28. }
  29. get(name) {
  30. if (typeof(name) !== "string") {
  31. throw "Name of submission must be an string.";
  32. }
  33. return this.#submissions[name];
  34. }
  35. add(content) {
  36. if (!(content instanceof submission)) {
  37. throw "New submission must be instance of submission class.";
  38. }
  39. if (content.name in this.#submissions) {
  40. throw "Trying to add submission which already exists.";
  41. }
  42. this.#submissions[content.name] = content;
  43. }
  44. clean() {
  45. this.#submissions = {};
  46. }
  47. }
  48. export { project };