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
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8cb4efd
Created a new folder 'users' inside the api folder. Added the index f…
anttiasmala Mar 5, 2024
dbd9c58
Created [uuid].ts file into api/users
anttiasmala Mar 5, 2024
08d2f7e
Copied request handlers from 'gifts'
anttiasmala Mar 5, 2024
100c393
Created types for user and creating user
anttiasmala Mar 5, 2024
486b359
Added user to not required field on CreateGift type
anttiasmala Mar 5, 2024
ea88381
Rewrote handleGET
anttiasmala Mar 5, 2024
5745929
Rewrote handlePOST
anttiasmala Mar 5, 2024
309784a
Copied this file from api/gifts/[uuid].ts
anttiasmala Mar 5, 2024
70251f9
Rewrote handleGET
anttiasmala Mar 5, 2024
6515f50
Rewrote handlePATCH
anttiasmala Mar 5, 2024
d6a5e94
Rewrote handlePUT
anttiasmala Mar 5, 2024
c3f4d4c
Rewrote handleDELETE
anttiasmala Mar 5, 2024
9f9f078
Created a new function for checking if email can be used for creating…
anttiasmala Mar 5, 2024
c72e3db
Changed regex pattern. AI made that for me
anttiasmala Mar 5, 2024
b1277f3
Lint fixes
anttiasmala Mar 5, 2024
92d3785
Installed Bcrypt and types for Bcrypt
anttiasmala Mar 5, 2024
af38e19
Added an import for bcrypt. Created function for hashing the password…
anttiasmala Mar 5, 2024
6d40868
Added some test requests into api.rest
anttiasmala Mar 5, 2024
2404aba
Changed 'gifts' to 'users' in the GET request's URL
anttiasmala Mar 11, 2024
25c9d27
Changed a full bcrypt import to only import 'hash'
anttiasmala Mar 11, 2024
bd8b9de
Changed email to be added as lowercased to the database
anttiasmala Mar 11, 2024
0aa81ae
Deleted isEmailFound check due to no need. Prisma handles this
anttiasmala Mar 11, 2024
e93272d
Added known Prisma errors
anttiasmala Mar 11, 2024
d1e570e
Added a DELETE request to api.rest
anttiasmala Mar 11, 2024
a03f714
Removed the IDs from requests due to they're not same for everyone
anttiasmala Mar 11, 2024
b89bc79
Added some comments to Requests
anttiasmala Mar 11, 2024
e00dc25
Changed PATCH request to PUT and added 'gift' field
anttiasmala Mar 11, 2024
77cfb55
Added a placeholder email field to User's PATCH request
anttiasmala Mar 11, 2024
1ff9c66
Added a DELETE request for Gift
anttiasmala Mar 11, 2024
6c97067
Changed PATCH request's email change to be lowercased
anttiasmala Mar 11, 2024
143cfcb
Changed how PUT request works a bit
anttiasmala Mar 11, 2024
81a110c
Added PUT requests to api.rest for future use
anttiasmala Mar 11, 2024
0eba44f
Changed isEmailValid function to not be a Promise anymore
anttiasmala Mar 11, 2024
1160168
Added values for PATCH request, were missing for some reason
anttiasmala Mar 11, 2024
4ebabcc
Fixed Invalid JSON error
anttiasmala Mar 11, 2024
5c973c1
Merge branch 'main' into antti/user-api
anttiasmala Mar 11, 2024
f2e7d08
Deleted unneccessary comments in api.rest
anttiasmala Mar 13, 2024
ffae3d5
Added mark to separate User requests and Gift requests
anttiasmala Mar 13, 2024
c2ea747
Added placeholder ID's to requests
anttiasmala Mar 13, 2024
b896e73
Made req.body as User to be fully optional. Made email to have condit…
anttiasmala Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pages/api/users/[uuid].ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ async function handlePUT({ req, res, queryUUID }: HandlerParams<User>) {
where: {
uuid: queryUUID,
},
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.

select: {
uuid: true,
firstName: true,
Expand Down