Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antti | api/user #18

Merged
merged 40 commits into from
Mar 14, 2024
Merged

Antti | api/user #18

merged 40 commits into from
Mar 14, 2024

Conversation

anttiasmala
Copy link
Collaborator

@anttiasmala anttiasmala commented Mar 5, 2024

Nyt on toimiva API myös käyttäjille. Tätä ei ole vielä linkitetty mihinkään login-sivuun vaan tein testit REST Clientillä. Käytin tässä vielä Insomniaa, tajusin liian myöhään tämän VS Coden REST Clientin. Pahoittelut tästä

Copy link

vercel bot commented Mar 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lahjalista ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 13, 2024 5:52pm

shared/types.ts Outdated
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nämä tulevat antti/user-model-branchista, käytin sitä pohjana vaikka siitäkin on PR #16

@anttiasmala
Copy link
Collaborator Author

Tästähän uupuu kokonaan tuo salasanan kryptaus, unohdin sen

@anttiasmala
Copy link
Collaborator Author

Tästähän uupuu kokonaan tuo salasanan kryptaus, unohdin sen

Nyt sekin on tehty! 👍

@anttiasmala anttiasmala requested a review from samuliasmala March 5, 2024 21:50
@anttiasmala anttiasmala linked an issue Mar 5, 2024 that may be closed by this pull request
@samuliasmala samuliasmala changed the base branch from main to dev March 7, 2024 19:10
@samuliasmala samuliasmala changed the base branch from dev to main March 7, 2024 19:10
Comment on lines +76 to +84
if (e instanceof PrismaClientKnownRequestError) {
if (e.code === 'P2025') {
return res.status(404).send('Record was not found!');
}
if (e.code === 'P2002') {
return res.status(400).send('Record was not unique!');
}
return res.status(500).send('Server error!');
}
Copy link
Collaborator Author

@anttiasmala anttiasmala Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tämä on kauhea tapa selvittää nämä errorit. Vaihdetaan parempaan kun PR #17 on valmis!

Comment on lines 92 to 96
data: newUserDetails,
data: {
email: newUserDetails.email.toLowerCase(),
firstName: newUserDetails.firstName,
lastName: newUserDetails.lastName,
},
Copy link
Collaborator Author

@anttiasmala anttiasmala Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muokkasin sitten tämän PUT-requestin toimimaan PATCH-requestina, koska nyt sieltä valitaan mitkä kentät halutaan tietokantaan muokata 😅 🤣

Annetaanko tässä kohtaa asian olla ja korjataan #19 issusessa vai onko järkevämpi korjata heti kutakuinkin näin:

async function handlePUT({ req, res, queryUUID }: HandlerParams<User>) {
  const newUserDetails = req.body as User;
  newUserDetails.email = newUserDetails.email.toLowerCase();

  const updatedUser = await prisma.user.update({
    where: {
      uuid: queryUUID,
    },
    data: newUserDetails,
    select: {
      uuid: true,
      firstName: true,
      lastName: true,
      email: true,
      createdAt: true,
      updatedAt: true,
    },
  });

  return res.status(200).json(updatedUser);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annetaan olla tässä kohtaa ja korjataan myöhemmin.

Comment on lines 92 to 96
data: newUserDetails,
data: {
email: newUserDetails.email.toLowerCase(),
firstName: newUserDetails.firstName,
lastName: newUserDetails.lastName,
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annetaan olla tässä kohtaa ja korjataan myöhemmin.

api.rest Outdated
Comment on lines 6 to 7
# ALL REQUESTS THAT ENDS WITH / WILL REQUIRE AN ID TO WORK!
# For example: GET {{baseUrl}}/gifts/2ebac01e-4586-4f2a-9fbd-486770ce04af
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mielestäni on paljon selkeämpi, että kyseisissä requesteissa on id valmiiksi laitettu, vaikka se ei vastaakaan mitään sinun tietokannan id:tä. Se on helppo korvata halutulla. Eli esim.

GET {{baseUrl}}/gifts/1141b4b1-7ea3-40dd-853c-1a0f9eecb4b5

parempi kuin että päättyy / merkkiin.

Copy link
Owner

@samuliasmala samuliasmala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hyvää työtä! 👍 Voi mergetä.

@anttiasmala anttiasmala merged commit 94d4017 into main Mar 14, 2024
5 checks passed
@anttiasmala anttiasmala deleted the antti/user-api branch March 14, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4. Luodaan API-rajapinnat käyttäjien muokkaamiseksi
2 participants