PetJournal / petjournal.api

API of the Pet Journal platform that helps you take care of your pet.
MIT License
15 stars 6 forks source link

Feature/pet name gender #44

Closed matheusgondra closed 1 year ago

matheusgondra commented 1 year ago

Updating the /pet route with the petName and gender fields.

The gender of the pet is only saved in the database as an "M" or "F" character. I tried to use an enum in prisma, but it was breaking everything and it was a lot of work to fix everything. So I decided to type it as a string and in the route validator I did the check

// omitted
const gender = input[this.fieldName].toUpperCase()

    if (typeof gender !== 'string') {
      return new InvalidParamError(this.fieldName)
    }

    if (!['M', 'F'].includes(gender)) {
      return new InvalidParamError(this.fieldName)
    }
// omitted