product.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Represents a product with various attributes.
  3. *
  4. * @class
  5. * @property {string|null} name - The name of the product
  6. * @property {string|null} description - A description of the product
  7. * @property {string|null} author - The author or creator of the product
  8. * @property {string|null} image - An image URL or reference for the product
  9. * @property {number|null} stock_count - The current inventory count
  10. * @property {string|null} barcode - The unique barcode identifier
  11. */
  12. export class product {
  13. name;
  14. description;
  15. author;
  16. image;
  17. stock_count;
  18. barcode;
  19. thumbnail;
  20. on_stock;
  21. constructor(target) {
  22. this.name = null;
  23. this.description = null;
  24. this.author = null;
  25. this.image = null;
  26. this.stock_count = null;
  27. this.barcode = null;
  28. this.thumbnail = null;
  29. this.on_stock = null;
  30. if ("name" in target) this.name = target["name"];
  31. if ("description" in target) this.description = target["description"];
  32. if ("author" in target) this.author = target["author"];
  33. if ("image" in target) this.image = target["image"];
  34. if ("stock_count" in target) this.stock_count = target["stock_count"];
  35. if ("barcode" in target) this.barcode = target["barcode"];
  36. if ("thumbnail" in target) this.thumbnail = target["thumbnail"];
  37. if ("on_stock" in target) this.on_stock = target["on_stock"];
  38. }
  39. get dump() {
  40. const dumped = {
  41. "name": this.name,
  42. "description": this.description,
  43. "author": this.author,
  44. "image": this.image,
  45. "stock_count": this.stock_count,
  46. "barcode": this.barcode,
  47. "thumbnail": this.thumbnail
  48. };
  49. if (this.on_stock !== null) {
  50. dumped["on_stock"] = this.on_stock;
  51. }
  52. return dumped;
  53. }
  54. get ready() {
  55. if (this.name === null || this.description === null) return false;
  56. if (this.author === null || this.image === null) return false;
  57. if (this.stock_count === null || this.barcode === null) return false;
  58. if (this.thumbnail === null) return false;
  59. return true;
  60. }
  61. copy() {
  62. return new product(this.dump);
  63. }
  64. }