I created a component called ‘userAchievements’ under collection ‘internal’. I added that component to the User content type with field name ‘achievements’. I do see that I have that component on the User object:
Now I created a custom service to update the user (as I will need to update him automatically when he reaches certain achievements) in ‘api/user/services/user.js’:
I think I was too fast to judge… For some reason it worked only once - I tried to reset the updated value and run the scenario again and the value wasn’t updated.
You should always specify the ID of the component that you want to update. Otherwise, it will be deleted and recreated. So the ID of the new component will change.
Is that a single component or a repeatable one?
In this example, you tried to update the User’s fields and not the component.
That example that you provided in the last post looks ok. It should work properly if your ctx.state.user.achievements.id exists.
Are you calling the strapi.services.user.updateUser service from the controller? Because services do not have access to the ctx object. Only you provide it to them. Can you try to output the ctx.state.user.achievements.id before calling the updateUser service?
The component is a single component. Basically I’m trying to group every possible achievement the user may have in a component instead of heaving separate fields in the User model.
That’s very confusing… I thought I’m updating the component’s fields in the User model.
Yes, it is being called from a controller and yes, ctx.state.user.achievements.id can be outputted before I call the updateUser service.
Last time I tried to run this scenario it worked again. I’ll try to reset the data and run the scenario again to see if it still works.