boolean-uk / team-dev-client-ex-2410-team3

0 stars 0 forks source link

API endpoint - POST: Post user #31

Open amos1969 opened 1 month ago

amos1969 commented 1 month ago

Create a user endpoint with the routing ('/users'). The "app.post" should take in firstname, lastname, email, bio, githubUrl, password from the request body. There should be a function which validates the fields password and email and then create a new user in the database and return a response of 201 with the json-formatted user if successful and a response of 400 if it fails.

app.post('/users', async (req, res) => {
  const { firstName, lastName, email, bio, githubUrl, password } = req.body

(Validation here)
 if (!password || password.length <= 8) {
    return {
      isValid: false,
      message: 'Password has to be more than 8 characters'
    }
  }

  try {
    const newUser = await User.create({
      firstName,
      lastName,
      email,
      bio,
      githubUrl,
      password
    })
    res.status(201).json({
      status: 'success',
      data: {
        user: newUser
      }
    })
  } catch (err) {
    res.status(400).json({
      status: 'fail',
      message: err.message
    })
  }
})
amos1969 commented 1 month ago

Where is the information that's coming in validated? I would include the expectation that it is already validated, if that's the case, or that it will be validated at the server layer, or both

sebgro98 commented 1 month ago

Jag skulle tro att du behöver kontrollera lite mer saker, unikt email, att password är rätt antal siffror osv

MayraMahamud commented 1 month ago

Jag skulle tro att du behöver kontrollera lite mer saker, unikt email, att password är rätt antal siffror osv @sebgro98

Okej, har vi fått några krav på valideringen som antal siffror på ett lösenord/namn osv och isåfall vart finns de?

sebgro98 commented 1 month ago

The email address must be in a valid format (e.g. abc@abc) The password should not be less than 8 characters in length The password should contain at least one uppercase character The password should contain at least one number The password should contain at least one special character

Dessa är dem ända kraven som finns

amos1969 commented 1 month ago

Approved