project.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 first_submission() {
  30. if (this.submissions.length < 1) {
  31. throw "In project must be minimum one submission to get first.";
  32. }
  33. return this.submissions[0];
  34. }
  35. get(name) {
  36. if (typeof(name) !== "string") {
  37. throw "Name of submission must be an string.";
  38. }
  39. return this.#submissions[name];
  40. }
  41. add(content) {
  42. if (!(content instanceof submission)) {
  43. throw "New submission must be instance of submission class.";
  44. }
  45. if (content.name in this.#submissions) {
  46. throw "Trying to add submission which already exists.";
  47. }
  48. this.#submissions[content.name] = content;
  49. }
  50. clean() {
  51. this.#submissions = {};
  52. }
  53. }
  54. export { project };