Add username existence check in customer registration and update handlers
This commit is contained in:
@@ -54,6 +54,7 @@ func (h *Handler) CreateCustomer(c echo.Context) error {
|
|||||||
customer, err := h.service.Register(c.Request().Context(), form)
|
customer, err := h.service.Register(c.Request().Context(), form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "customer with this email already exists" ||
|
if err.Error() == "customer with this email already exists" ||
|
||||||
|
err.Error() == "customer with this username already exists" ||
|
||||||
err.Error() == "company with this name already exists" ||
|
err.Error() == "company with this name already exists" ||
|
||||||
err.Error() == "company with this registration number already exists" ||
|
err.Error() == "company with this registration number already exists" ||
|
||||||
err.Error() == "company with this tax ID already exists" {
|
err.Error() == "company with this tax ID already exists" {
|
||||||
@@ -126,6 +127,7 @@ func (h *Handler) UpdateCustomer(c echo.Context) error {
|
|||||||
return response.NotFound(c, "Customer not found")
|
return response.NotFound(c, "Customer not found")
|
||||||
}
|
}
|
||||||
if err.Error() == "customer with this email already exists" ||
|
if err.Error() == "customer with this email already exists" ||
|
||||||
|
err.Error() == "customer with this username already exists" ||
|
||||||
err.Error() == "company with this name already exists" ||
|
err.Error() == "company with this name already exists" ||
|
||||||
err.Error() == "company with this registration number already exists" ||
|
err.Error() == "company with this registration number already exists" ||
|
||||||
err.Error() == "company with this tax ID already exists" {
|
err.Error() == "company with this tax ID already exists" {
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ func (s *customerService) Register(ctx context.Context, form *CreateCustomerForm
|
|||||||
return nil, errors.New("customer with this email already exists")
|
return nil, errors.New("customer with this email already exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if username already exists
|
||||||
|
existingCustomer, _ = s.repository.GetByUsername(ctx, strings.ToLower(form.Username))
|
||||||
|
if existingCustomer != nil {
|
||||||
|
return nil, errors.New("customer with this username already exists")
|
||||||
|
}
|
||||||
|
|
||||||
// Check validator
|
// Check validator
|
||||||
if !s.validator.IsValidUsername(form.Username) {
|
if !s.validator.IsValidUsername(form.Username) {
|
||||||
return nil, errors.New("invalid username format")
|
return nil, errors.New("invalid username format")
|
||||||
|
|||||||
Reference in New Issue
Block a user