Image in the model isn't replaced after loading a new image

Hello!
I have added one image field (avatar) to the standard user model. I also created a new endpoint to upload the user’s avatar. This endpoint works fine if the user doesn’t have an avatar. However, if the user already has an avatar, the new avatar uploaded via my new endpoint doesn’t replace the user’s old avatar (while the new avatar appears in the media library, that is, the new avatar is not attached to the user).

I’m using the following code to upload avatars in the my endpoint:

const attachment = await strapi.plugins.upload.services.upload.upload({
    data: {
        refId: user.id,
        ref: 'plugin::users-permissions.user',
        field: 'avatar'
    },
    files: avatar,
});

Do you have any ideas how to fix it?

Thanks in advance!

Hello! Did you manage to solve the problem? If so, how?