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

the get image endpoint and cardPut with the image #45

Merged
merged 40 commits into from
Aug 30, 2021
Merged

Conversation

chomosuke
Copy link
Owner

@chomosuke chomosuke commented Aug 28, 2021

Turns out a certain member of our team is right again, image turns out to be very easy.

Closes #23 and #30

This suffer from the same problem as #43

Note that this pull request does not address #25 and #26, which I'm hoping for someone else to do.

@chomosuke chomosuke self-assigned this Aug 28, 2021
@chomosuke chomosuke added this to the Sprint 1 milestone Aug 28, 2021
@chomosuke chomosuke added this to In progress in Sprint 1 via automation Aug 28, 2021
@chomosuke chomosuke added this to Sprint 1 in Product backlog via automation Aug 28, 2021
@chomosuke chomosuke added the enhancement New feature or request label Aug 28, 2021
Copy link
Collaborator

@shangzhel shangzhel left a comment

Choose a reason for hiding this comment

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

Almost done. Minor changes needed, but remove server/package-lock.json. I suspect it got there because you ran npm install inside server.

package.json Outdated
@@ -23,5 +23,9 @@
"server",
"shared",
"web"
]
],
"dependencies": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The dependencies are already added to server/package.json. They do not need to be here.

@@ -6,6 +6,7 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: [
'src/__tests__/(.*\.)?helpers.[jt]sx?$'
'src/__tests__/(.*\.)?helpers.[jt]sx?$',
'src/__tests__/api/authenticated/imageUri.ts'
Copy link
Collaborator

Choose a reason for hiding this comment

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

The helpers rule above exists so that test-exclusive helper files do not trigger test failures. Rename imageUri.ts to image.helpers.ts instead.

import { HttpStatusError } from '../../../api/HttpStatusError';
import { imageUri } from './imageUri';

describe('cardPut unit tests', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Describe the tests with its route name: PUT /api/card unit tests

import { User } from './auth';
import { mockRequest } from './helpers';

describe('image unit tests', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Describe the unit tests with its route name: /api/image unit tests

throw new HttpStatusError(404);
}
const imageData = cardDoc.image;
if (imageData === undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use == null to relax the test so that it catches both undefined and null.

throw new HttpStatusError(400);
}
try {
image = await Jimp.read(Buffer.from(image.substr(dataURIPrefix.length), 'base64'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not reuse the image variable. Store the results of the Jimp buffer in a new variable.

} catch (e) {
throw new HttpStatusError(400);
}
image = await image.getBufferAsync(Jimp.MIME_JPEG);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, do not reuse the image variable, store the buffer in a new variable.

email: cardDoc.email,
jobTitle: cardDoc.jobTitle,
company: cardDoc.company,
hasImage: !!cardDoc.image,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not use the double negation pattern to get a boolean. Compare it against null instead: cardDoc.image != null.

@chomosuke chomosuke requested review from shangzhel and removed request for shangzhel August 29, 2021 14:36
@shangzhel
Copy link
Collaborator

Revert e5925d1 because requestLimiter is useless

This reverts commit e5925d1, reversing
changes made to 70adeed.
Copy link
Collaborator

@shangzhel shangzhel left a comment

Choose a reason for hiding this comment

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

Just one unsanitized input usage, fix that and it will be good to go.

server/src/api/authenticated/image.ts Outdated Show resolved Hide resolved
const { cardId } = params;

try {
Types.ObjectId(cardId);
Copy link
Collaborator

@shangzhel shangzhel Aug 30, 2021

Choose a reason for hiding this comment

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

I meant also saving the ObjectId into a local variable then passing it into findById later.

Copy link
Owner Author

Choose a reason for hiding this comment

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

wait but it essentially does the same thing no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mongoose will perform the conversion by itself one more time if the argument type does not match.

Copy link
Collaborator

@shangzhel shangzhel left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@chomosuke chomosuke merged commit fb33776 into master Aug 30, 2021
Sprint 1 automation moved this from In review to Done Aug 30, 2021
Product backlog automation moved this from Sprint 1 to Sprint 1 Done Aug 30, 2021
@chomosuke chomosuke removed the request for review from pep1032314 August 30, 2021 15:33
@chomosuke chomosuke deleted the richard/image branch August 30, 2021 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Product backlog
  
Sprint 1 Done
Sprint 1
  
Done
Development

Successfully merging this pull request may close these issues.

Implement Card Create Endpoint -- PUT @ api/card
3 participants