reservation_factory.js 854 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { reservation } from "./reservation.js";
  2. export class reservation_factory {
  3. #target;
  4. constructor() {
  5. this.#target = new reservation();
  6. }
  7. phone_number(target) {
  8. target = target.trim().replaceAll("-", "");
  9. if (target.length === 0) {
  10. target = null;
  11. }
  12. this.#target.phone_number = target;
  13. return this;
  14. }
  15. email(target) {
  16. target = target.trim();
  17. if (target.length === 0) {
  18. target = null;
  19. }
  20. this.#target.email = target;
  21. return this;
  22. }
  23. product(target) {
  24. this.#target.product_barcode = target.barcode;
  25. return this;
  26. }
  27. result() {
  28. if (this.#target.ready) {
  29. return this.#target;
  30. }
  31. throw new Error("Target reservation is not ready yet.");
  32. }
  33. }