• Caveman@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    10 days ago

    I like the service but the constructor parameter is really bad and makes the methods less reusable

    • dohpaz42@lemmy.world
      link
      fedilink
      English
      arrow-up
      2
      ·
      10 days ago

      That’s fair. How would you go about implementing the service? I always love seeing other people’s perspectives. 😊

      • Caveman@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        9 days ago

        More or less the same but the user gets passed as a method parameter each time. Validators would be in my opinion a long function inside the service also with named variables like this because it’s just easy to read and there are no surprises. I’d probably refactor it at around 5 conditions or 30 lines of validation logic.

        I recommend trying out using the constructor in services for tools such as a database and methods for data such as user. It will be very easy to use everywhere and for many users and whatever

        const passwordIsValid = ...
        if (!passwordIsValid){
          return whatever
        }