User.js 820 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * User model with name and email properties
  3. */
  4. class User {
  5. /**
  6. * Creates a new User instance
  7. * @param {string} name - User's name
  8. * @param {string} email - User's email address
  9. */
  10. constructor(name, email) {
  11. this.name = name;
  12. this.email = email;
  13. }
  14. /**
  15. * Returns a plain object representation of the user
  16. * @returns {Object} User data as plain object
  17. */
  18. toObject() {
  19. return {
  20. name: this.name,
  21. email: this.email
  22. };
  23. }
  24. /**
  25. * Creates a new User with updated properties (immutable update)
  26. * @param {Object} updates - Properties to update
  27. * @returns {User} New User instance with updates applied
  28. */
  29. update(updates) {
  30. return new User(
  31. updates.name ?? this.name,
  32. updates.email ?? this.email
  33. );
  34. }
  35. }
  36. module.exports = User;