mercurjs / mercur-api-starter

5 stars 9 forks source link

fix: localize the class and pass the external validator AdminUpdateUserRequest to register it to be used #31

Open aidrecabrera opened 1 month ago

aidrecabrera commented 1 month ago

This PR fixes the issue where the custom validator for AdminUpdateUserRequest was not being properly registered, which caused validation errors when updating user statuses in the admin UI. The fix involves correctly registering the overridden validator to ensure the status field is recognized and validated. The issue was mentioned in #30. The fix was to register the AdminUpdateUserRequest using registerOverriddenValidators to replace the core validator.

Without registering the custom AdminUpdateUserRequest, Medusa's default validation kicks in and fails to recognize the custom status field. This results in errors like:

{"type":"invalid_data","message":"property status should not exist"}

So to fix this, we have to register the custom validator as documented here. This will ensure that our extended request (with the status field) is properly validated. I tested it and the status field is now validated correctly when updating a user. Further information on extending and registering custom validators can be found in the Medusa docs.

Example Demonstration

25af840d-8aba-4972-a0ef-2fa097c5d249.webm

a33ea09f-368a-493a-aa02-02274c4ae79b.webm