-
Notifications
You must be signed in to change notification settings - Fork 0
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
Antti | api/user #18
Conversation
… a new user. It checks as well if the email is used already. Added error messages for couple errors
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
shared/types.ts
Outdated
There was a problem hiding this comment.
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
Tästähän uupuu kokonaan tuo salasanan kryptaus, unohdin sen |
…. Changed the password used for storing to be hashed one
Nyt sekin on tehty! 👍 |
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!'); | ||
} |
There was a problem hiding this comment.
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!
pages/api/users/[uuid].ts
Outdated
data: newUserDetails, | ||
data: { | ||
email: newUserDetails.email.toLowerCase(), | ||
firstName: newUserDetails.firstName, | ||
lastName: newUserDetails.lastName, | ||
}, |
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
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.
pages/api/users/[uuid].ts
Outdated
data: newUserDetails, | ||
data: { | ||
email: newUserDetails.email.toLowerCase(), | ||
firstName: newUserDetails.firstName, | ||
lastName: newUserDetails.lastName, | ||
}, |
There was a problem hiding this comment.
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
# ALL REQUESTS THAT ENDS WITH / WILL REQUIRE AN ID TO WORK! | ||
# For example: GET {{baseUrl}}/gifts/2ebac01e-4586-4f2a-9fbd-486770ce04af |
There was a problem hiding this comment.
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.
There was a problem hiding this 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ä.
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ä