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

✨ PATCH items (CRUD) #267

Merged

Conversation

brunobuddy
Copy link
Contributor

@brunobuddy brunobuddy commented Jan 20, 2025

Description

This PRs removes an ambiguity updating items (see #265). Updating an item leaving props and relations blank/empty results in a strange behavior:

  • empty props are not deleted (original value is conserved)
  • relations are deleted

This PRs distinguishes between both behaviors by proposing a PATCH method in addition to the PUT method:

  • PUT method does a full replacement of props and relations (empty props/relations are considered deleted)

  • PATCH method does a partial update touching only the props and relations present in the body

  • Related DOC PR

Related Issues

How can it be tested?

Get the related doc from the website repository replacing docs/fetch-content.sh by

#!/bin/bash
# Remove the existing directory if it exists
rm -rf content

# Clone the repository into the 'content' directory
git clone --depth 1 --branch patch https://github.com/mnfst/docs.git content

And then run npm run fetch-content and browse the documentation to play around.

I recommend using Postman to update existing items that have relations with both PUT and PATCH methods to see if it does as it says.

Impacted packages

Check the NPM packages that require a new publication or release:

Check list before submitting

  • I created the related changeset for my changes with npx changeset
  • I have performed a self-review of my code (no debugs, no commented code, good naming, etc.)
  • I wrote the relative tests
  • I created a PR for the documentation if necessary and attached the link to this PR
  • This PR is wrote in a clear language and correctly labeled

@brunobuddy brunobuddy linked an issue Jan 20, 2025 that may be closed by this pull request
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

Attention: Patch coverage is 75.55556% with 11 lines in your changes missing coverage. Please review.

Project coverage is 60.71%. Comparing base (f32492d) to head (b250eeb).
Report is 20 commits behind head on master.

Files with missing lines Patch % Lines
...est/src/open-api/services/open-api-crud.service.ts 0.00% 6 Missing ⚠️
...es/core/manifest/src/crud/services/crud.service.ts 78.57% 3 Missing ⚠️
...nifest/src/entity/services/relationship.service.ts 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #267      +/-   ##
==========================================
+ Coverage   56.39%   60.71%   +4.32%     
==========================================
  Files          42       42              
  Lines        1204     1227      +23     
  Branches      298      310      +12     
==========================================
+ Hits          679      745      +66     
+ Misses        486      444      -42     
+ Partials       39       38       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brunobuddy brunobuddy requested a review from SebConejo January 20, 2025 16:17
@brunobuddy brunobuddy self-assigned this Jan 20, 2025
@brunobuddy brunobuddy added the core Core issues label Jan 20, 2025
@brunobuddy brunobuddy marked this pull request as ready for review January 20, 2025 16:21
@SebConejo SebConejo self-requested a review January 21, 2025 14:31
Copy link
Contributor

@SebConejo SebConejo left a comment

Choose a reason for hiding this comment

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

on my test, I had Food related to several cats. When I updated the food name using a patch method, I lost the relation with the cats.

Before:
Capture d’écran 2025-01-21 à 15 34 35

Patch:
Capture d’écran 2025-01-21 à 15 35 00

After:
Capture d’écran 2025-01-21 à 15 35 07

@brunobuddy brunobuddy merged commit 0eecb95 into master Jan 23, 2025
8 checks passed
@brunobuddy brunobuddy deleted the 265-updates-clear-all-the-item-entity-relationship-fields branch January 23, 2025 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updates clear all the item entity relationship fields Failing if entity relation name is same as entity name
2 participants