-
Notifications
You must be signed in to change notification settings - Fork 2
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
Cloudinary Setup/IN #51
Conversation
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.
Great work! Left you some comments, happy to see you did some data validation.
One piece of advice regarding the PR template, if you aren't using a section then remove it. And be a bit more descriptive in it!
Also, this was more back-end (BE) work rather than integration (IN)
server/controllers/profile.js
Outdated
// @route POST /profile/create | ||
// @desc Create new profile | ||
// @access Public |
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.
Good job on documentation!
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.
Thank you sir!
server/controllers/profile.js
Outdated
try { | ||
const { | ||
firstName, | ||
lastName, | ||
gender, | ||
birthday, | ||
email, | ||
phoneNumber, | ||
location, | ||
profilePic, | ||
description, | ||
availability, | ||
} = req.body; | ||
const profile = await Profile.create({ | ||
firstName, | ||
lastName, | ||
gender, | ||
birthday, | ||
email, | ||
phoneNumber, | ||
location, | ||
profilePic, | ||
description, | ||
availability, | ||
}); | ||
|
||
res.status(201).json({ | ||
profile, | ||
}); | ||
} catch (err) { | ||
res.status(500); | ||
throw new Error("Something went wrong, please try again"); | ||
} |
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.
So, the try/catch
here is actually not needed. Now, in other applications maybe but in this one we utilize express-async-handler
which actually will catch thrown errors and respond with JSON instead of crashing the application. This actually doesn't give us any context into an error that occurs.
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.
Please remove in all applicable cases - now, let me mention. If we're try/catch
for specific errors that are expected then of course we can keep that in!
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.
@moffatethan My apologies, this was actually a mix up from an old version. You have made the correction in profile controllers and I have made the changes already.
Well noted!
server/controllers/profile.js
Outdated
description, | ||
availability, | ||
}, | ||
{ new: true } |
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.
Good work!
server/controllers/profile.js
Outdated
res.status(400); | ||
throw new Error("Failed to upload photo, ensure that you have selected a valid file format") | ||
} | ||
const { secure_url } = await cloudinary.uploader.upload(file.path, { |
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.
Nice destructuring here and utilizing folders for organization!
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.
I just want to add here for future cases that we can often leverage the :
syntax and rename destructured fields to better fit our conventions (example).
server/controllers/profile.js
Outdated
profile.addPhoto(secure_url, "profilePic"); | ||
|
||
res.status(200).json({ | ||
msg: "Image uploaded successfully", |
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.
I would do message
instead of msg
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.
Good, please fix merge conflicts then I will approve!
What this PR does (required):
Screenshots / Videos (front-end only):
Any information needed to test this feature (required):
Any issues with the current functionality (optional):