product_base.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. try {
  15. this.stock_count = Number(this.stock_count);
  16. } catch {
  17. this.stock_count = 0;
  18. }
  19. }
  20. }
  21. get dump() {
  22. return {
  23. "name": new String(this.name),
  24. "description": new String(this.description),
  25. "author": new String(this.author),
  26. "barcode": new String(this.barcode),
  27. "stock_count": new String(this.stock_count)
  28. }
  29. }
  30. _extract(dict, name) {
  31. if (dict === null) {
  32. return null;
  33. }
  34. if (name in dict) {
  35. return dict[name];
  36. }
  37. return null;
  38. }
  39. get avairable() {
  40. return (this.stock_count > 0);
  41. }
  42. }