Hello friends, I have a question about components:
I created a content type using components to reuse the data.
Account:
{
"data": {
"personalInfo": {
"firstName": "John",
"lastName": "Doe",
"fullName": "John Doe"
},
"contactInfo": {
"email": "johndoe@emme.ly",
"phone": "1111112",
"additionalPhone": "2222221"
},
"addressInfo": {
"address": "Chapman Rd.",
"complement": "260",
"zipCode": "36445",
"state": "Frisco",
"city": "AL"
}
}
}
Where the components are, personalInfo
, contactInfo
and addressInfo
.
POST
works correctly.
But when I need to use PUT
without updating all fields, it returns null
.
{
"data": {
"personalInfo": {
"fullName": "John Doe"
},
"contactInfo": {
"email": "johndoe@emme.ly",
"phone": "1111112",
"additionalPhone": "2222221"
},
"addressInfo": {
"address": "Chapman Rd.",
"complement": "260",
"zipCode": "36445",
"state": "Frisco",
"city": "AL"
}
}
}
Return:
{
"data": {
"id": 20,
"blocked": false,
"slug": "6b634de9-026c-4830-ac81-bdd0cb059da5",
"createdAt": "2022-12-13T17:30:42.479Z",
"updatedAt": "2022-12-13T17:35:24.335Z",
"locale": "en",
"personalInfo": {
"id": 26,
"firstName": null,
"lastName": null,
"fullName": "John Doe"
},
"contactInfo": {
"id": 22,
"email": "johndoe@emme.ly",
"phone": "1111112",
"additionalPhone": "2222221"
},
"addressInfo": {
"id": 45,
"address": "Chapman Rd.",
"complement": "260",
"zipCode": "36445",
"city": "AL",
"state": "Frisco",
"gate": null,
"latitude": null,
"longitude": null
}
},
"meta": {}
}
Note that I didn’t pass firstName
and lastName
from the personalInfo
component because as it’s a PUT
I only really want to update what I need.
My doubts are:
- Is this behavior normal? From what I’ve read in the documentation, if you don’t pass the
ID
of the component it recreates the data, I think that’s why it’s returning asnull
; - Is there any simple solution for this, for me to pass only the fields that need to be updated and change only him?
Thank you all.