Skip to content

Project 3 - Backend (Ian Lau, Qian Ling, Charles Lee)#53

Open
charlesleezhaoyi wants to merge 177 commits intorocketacademy:mainfrom
charlesleezhaoyi:main
Open

Project 3 - Backend (Ian Lau, Qian Ling, Charles Lee)#53
charlesleezhaoyi wants to merge 177 commits intorocketacademy:mainfrom
charlesleezhaoyi:main

Conversation

@charlesleezhaoyi
Copy link

No description provided.

charlesleezhaoyi and others added 30 commits March 15, 2024 21:03
…t before creating, using findOrCreate method
Qiannnly and others added 29 commits April 9, 2024 20:03
Updated with email Consent and email notification in accpetRequest
@@ -1 +1,2 @@
node_modules/ No newline at end of file

Choose a reason for hiding this comment

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

no README

Comment on lines +63 to +69
app.use("/categories", checkJwt, categoriesRouter.routes());
app.use("/users", checkJwt, usersRouter.routes());
app.use("/posts", checkJwt, postsRouter.routes());
app.use("/books", checkJwt, booksRouter.routes());
app.use("/comments", checkJwt, commentsRouter.routes());
app.use("/requests", checkJwt, requestsRouter.routes());
app.use("/donations", checkJwt, donationsRouter.routes());

Choose a reason for hiding this comment

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

if all your routes are protected, why not just do

app.use(checkJwt)

instead of defining this on every base route?

key: "id",
},
},
beneId: {

Choose a reason for hiding this comment

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

i wouldn't name a property like such, as it is not clear to everyone. Everytime I read this, I need to think what bene is

}
like.init(
{
likerId: {

Choose a reason for hiding this comment

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

why not just userId?

}
comment.init(
{
commentedPostId: {

Choose a reason for hiding this comment

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

why not just postId ?

Comment on lines +49 to +64
if (recipient.smsConsent && recipient.phone) {
await client.messages.create({
body: `Your request has been accepted. Please contact this number ${donation.donor.phone} or email ${donation.donor.email} to arrange a pick up time & location.`,
from: process.env.DB_TWILIO_TEST_NUMBER,
to: recipient.phone,
});
}
if (recipient.emailConsent) {
await mailjetRequest.request({
Messages: [
{
From: {
Email: process.env.MAILJET_SENDER,
Name: "Book Swap",
},
To: [

Choose a reason for hiding this comment

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

When building integrations with such services, I would definitely recommend more fine-grained structure to your github repository. We can introduce multiple layers to our architecture. Here we could make use of services, which handle the business logic and we only use the controllers for accepting requests and sending responses.

You can look up three-tier architecture, hexagonal architecture, domain driven design, and other concepts for this.

email: email,
},
});
await requester.addRequesterDonation(donation, {

Choose a reason for hiding this comment

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

what if requester is undefined?

},
}
);
return res.json("Okay");

Choose a reason for hiding this comment

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

Why the Okay string? Seems like status code 200 would already be "Okay". What use does this string serve? :)

try {
this.checkStringFromParams(email, "email");
const data = await this.userModel.findOne({ where: { email: email } });
return res.json(data);

Choose a reason for hiding this comment

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

here you are returning the user's email and the user's phone number, just based off receiving a token. I could be a user, and enter any other user's email address in the params, and get all their sensitive information. Please be aware of this :)

Comment on lines +60 to +63
await this.userModel.update(
{ firstName, lastName, phone, smsConsent, emailConsent },
{ where: { email: email } }
);

Choose a reason for hiding this comment

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

Same here. I can probably update another user's information on this endpoint, as long as I have an own account/token, that I pass with the request. You should try it :)

  1. Login
  2. Make a request (check network tab for token attached to request)
  3. Copy token
  4. Open Postman
  5. Make request against this endpoint with your token and another user's email
  6. Check DB if that user's data has been updated

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 participants