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
+2 -12
View File
@@ -53,12 +53,7 @@ func (h *Handler) CreateCustomer(c echo.Context) error {
customer, err := h.service.Register(c.Request().Context(), form)
if err != nil {
if err.Error() == "customer with this email already exists" ||
err.Error() == "customer with this username already exists" ||
err.Error() == "customer with this phone number already exists" ||
err.Error() == "company with this name already exists" ||
err.Error() == "company with this registration number already exists" ||
err.Error() == "company with this tax ID already exists" {
if isCustomerConflictError(err) {
return response.Conflict(c, err.Error())
}
if strings.HasPrefix(err.Error(), "invalid company ID") || err.Error() == "invalid username format" {
@@ -127,12 +122,7 @@ func (h *Handler) UpdateCustomer(c echo.Context) error {
if err.Error() == "customer not found" {
return response.NotFound(c, "Customer not found")
}
if err.Error() == "customer with this email already exists" ||
err.Error() == "customer with this username already exists" ||
err.Error() == "customer with this phone number already exists" ||
err.Error() == "company with this name already exists" ||
err.Error() == "company with this registration number already exists" ||
err.Error() == "company with this tax ID already exists" {
if isCustomerConflictError(err) {
return response.Conflict(c, err.Error())
}
if strings.HasPrefix(err.Error(), "invalid company ID") {