fix(user,customer): return 409 on phone duplicate-key races

Map E11000 from the per-collection phone index to friendly conflict
errors and skip redundant GetByPhone when the phone is unchanged.

Not blocking: IAT test DB may need a one-off dedupe for index build;
phone uniqueness is per collection (users vs customers), not global.
This commit is contained in:
Mazyar
2026-06-06 20:34:45 +03:30
parent 0da0c8b8c9
commit 22487eaef5
7 changed files with 143 additions and 20 deletions
+9
View File
@@ -170,6 +170,9 @@ func (h *Handler) UpdateProfile(c echo.Context) error {
user, err := h.service.Update(c.Request().Context(), userID, form)
if err != nil {
if isUserConflictError(err) {
return response.Conflict(c, err.Error())
}
return response.BadRequest(c, err.Error(), "")
}
@@ -274,6 +277,9 @@ func (h *Handler) CreateUser(c echo.Context) error {
// Call service
user, err := h.service.Register(c.Request().Context(), form)
if err != nil {
if isUserConflictError(err) {
return response.Conflict(c, err.Error())
}
return response.BadRequest(c, err.Error(), "")
}
@@ -386,6 +392,9 @@ func (h *Handler) UpdateUser(c echo.Context) error {
// Call service
user, err := h.service.Update(c.Request().Context(), idStr, form)
if err != nil {
if isUserConflictError(err) {
return response.Conflict(c, err.Error())
}
return response.BadRequest(c, err.Error(), "")
}