product_base.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export class product_base {
  2. name;
  3. description;
  4. author;
  5. barcode;
  6. stock_count;
  7. constructor(target = null) {
  8. this.name = this._extract(target, "name");
  9. this.description = this._extract(target, "description");
  10. this.author = this._extract(target, "author");
  11. this.barcode = this._extract(target, "barcode");
  12. this.stock_count = this._extract(target, "stock_count");
  13. if (this.stock_count !== null) {
  14. this.stock_count = Number(this.stock_count);
  15. }
  16. }
  17. get dump() {
  18. return {
  19. "name": this.name,
  20. "description": this.description,
  21. "author": this.author,
  22. "barcode": this.barcode,
  23. "stock_count": this.stock_count
  24. }
  25. }
  26. _extract(dict, name) {
  27. if (dict === null) {
  28. return null;
  29. }
  30. if (name in dict) {
  31. return dict[name];
  32. }
  33. return null;
  34. }
  35. get avairable() {
  36. return (this.stock_count > 0);
  37. }
  38. }