Skip to content

Conversation

@chpy04
Copy link
Contributor

@chpy04 chpy04 commented Mar 29, 2025

Changes

Create, update, and delete endpoints for parts, along with an upload preview image endpoint to upload an image as the preview for a part

Test Cases

  • creating a part works
  • updating a part works
  • deleting a part works
  • non-leadership cannot create part
  • non-leadership cannot update part
  • cannot update deleted part

Screenshots

Screenshot 2025-03-29 at 2 17 35 PM Screenshot 2025-03-29 at 2 25 36 PM Screenshot 2025-03-29 at 2 26 03 PM

Checklist

It can be helpful to check the Checks and Files changed tabs.
Please review the contributor guide and reach out to your Tech Lead if anything is unclear.
Please request reviewers and ping on slack only after you've gone through this whole checklist.

  • All commits are tagged with the ticket number
  • No linting errors / newline at end of file warnings
  • All code follows repository-configured prettier formatting
  • No merge conflicts
  • All checks passing
  • Screenshots of UI changes (see Screenshots section)
  • Remove any non-applicable sections of this template
  • Assign the PR to yourself
  • No yarn.lock changes (unless dependencies have changed)
  • Request reviewers & ping on Slack
  • PR is linked to the ticket (fill in the closes line below)

Closes #3311

@chpy04 chpy04 requested review from Zwendle and gcooper407 March 29, 2025 19:44
Copy link
Contributor

@gcooper407 gcooper407 left a comment

Choose a reason for hiding this comment

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

Looks perfect!

const partsRouter = express.Router();

partsRouter.post(
'/:wbsNum/create',
Copy link
Member

Choose a reason for hiding this comment

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

It would really be better to have the wbs in the body here -- the path expands to /parts/:wbsNum/create which implies that wbsNum is an identifier for a part (like the param in the same location on other routes is). It also makes things more standard to avoid path params on create

try {
const { partId } = req.params;
const deletedPart = await PartReviewService.deletePart(partId, req.currentUser, req.organization.organizationId);
res.status(200).json(deletedPart);
Copy link
Member

Choose a reason for hiding this comment

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

nit: usually it makes more sense to return a success message on delete

const updatedPart = await prisma.part.update({
where: { partId },
data: {
previewImageLink: previewImageData.id
Copy link
Member

Choose a reason for hiding this comment

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

We should change this field name in the schema, it's an id, not a link

submitter.userId === part.userCreated.userId;
if (!hasPermission) throw new AccessDeniedException('Only leadership and part creators can add a preview image');

const previewImageData = await uploadFile(previewImage);
Copy link
Member

Choose a reason for hiding this comment

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

nit: you can use destructuring here


if (!hasPermission) throw new AccessDeniedException('Only leadership and the part creator can delete a part');

const deletedPart = await prisma.part.update({
Copy link
Member

Choose a reason for hiding this comment

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

You have to add the user here too

await resetUsers();
});

it('creates a part, updates it, and deletes it', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

We need exception tests for deletion

* @param submitter the user making the update
* @param organization the organization
*/
static async uploadPreview(previewImage: Express.Multer.File, partId: string, submitter: User, organizationId: string) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: name uploadPartPreviewImage or similar to be more specific

* @param submitter the user making the update
* @param organization the organization
*/
static async uploadPreview(previewImage: Express.Multer.File, partId: string, submitter: User, organizationId: string) {
Copy link
Member

Choose a reason for hiding this comment

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

We should enforce a size of <= 1 MB here

@walker-sean walker-sean merged commit 20cc10a into feature/cad-project-file-review Apr 5, 2025
4 checks passed
@walker-sean walker-sean deleted the #3311-CUD-endpoints-for-parts branch April 5, 2025 21:11
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