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

Cloudinary Setup/IN #51

Merged
merged 20 commits into from
Oct 19, 2021
Merged

Cloudinary Setup/IN #51

merged 20 commits into from
Oct 19, 2021

Conversation

Gamey001
Copy link
Collaborator

@Gamey001 Gamey001 commented Oct 6, 2021

What this PR does (required):

  • Allows a user to upload profile and other images

Screenshots / Videos (front-end only):

Any information needed to test this feature (required):

  • Postman REST client needed

Any issues with the current functionality (optional):

  • none

Copy link
Contributor

@moffatethan moffatethan left a 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)

Comment on lines 5 to 7
// @route POST /profile/create
// @desc Create new profile
// @access Public
Copy link
Contributor

Choose a reason for hiding this comment

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

Good job on documentation!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you sir!

Comment on lines 9 to 41
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");
}
Copy link
Contributor

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.

Copy link
Contributor

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!

Copy link
Collaborator Author

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!

description,
availability,
},
{ new: true }
Copy link
Contributor

Choose a reason for hiding this comment

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

Good work!

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, {
Copy link
Contributor

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!

Copy link
Collaborator

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).

profile.addPhoto(secure_url, "profilePic");

res.status(200).json({
msg: "Image uploaded successfully",
Copy link
Contributor

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

server/middleware/multer.js Outdated Show resolved Hide resolved
server/routes/profile.js Show resolved Hide resolved
@moffatethan moffatethan changed the base branch from main to Cloudinary-Setup October 8, 2021 17:12
@moffatethan moffatethan mentioned this pull request Oct 8, 2021
@Gamey001 Gamey001 linked an issue Oct 10, 2021 that may be closed by this pull request
Copy link
Contributor

@moffatethan moffatethan left a 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!

@Gamey001 Gamey001 linked an issue Oct 14, 2021 that may be closed by this pull request
@Gamey001 Gamey001 changed the title Cloudinary IN Cloudinary Setup/IN Oct 14, 2021
@Gamey001 Gamey001 merged commit 9337cd4 into Cloudinary-Setup Oct 19, 2021
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.

IN: Cloudinary Setup: Cloudinary
3 participants