reservation.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. export class reservation {
  2. email;
  3. phone_number;
  4. product_barcode;
  5. constructor(target = null) {
  6. this.email = null;
  7. this.phone_number = null;
  8. this.product_barcode = null;
  9. if (target === null) {
  10. return ;
  11. }
  12. if ("email" in target) {
  13. this.email = target["email"];
  14. }
  15. if ("target_barcode" in target) {
  16. this.product_barcode = target["target_barcode"];
  17. }
  18. if ("phone_number" in target) {
  19. this.phone_number = target["phone_number"];
  20. }
  21. }
  22. get dump() {
  23. const dumped = {
  24. "target_barcode": this.product_barcode
  25. };
  26. if (this.email !== null) {
  27. dumped["email"] = this.email;
  28. }
  29. if (this.phone_number !== null) {
  30. dumped["phone_number"] = this.phone_number;
  31. }
  32. return dumped;
  33. }
  34. get ready() {
  35. if (this.product_barcode === null) return false;
  36. if (this.email === null && this.phone_number === null) return false;
  37. return true;
  38. }
  39. copy() {
  40. return new reservation(this.dump);
  41. }
  42. }