arreglos varios antes de la primera version en produccion

This commit is contained in:
2026-07-08 18:57:01 +02:00
parent 8c381d98a6
commit 61a43ef481
3 changed files with 110 additions and 43 deletions
+9 -17
View File
@@ -35,6 +35,9 @@ var eaAllowedRoutes = []struct {
{http.MethodGet, regexp.MustCompile(`^/ea-api/v1/services/?$`)},
{http.MethodGet, regexp.MustCompile(`^/ea-api/v1/availabilities/?$`)},
{http.MethodGet, regexp.MustCompile(`^/ea-api/v1/providers/\d+/?$`)},
// Solo este ajuste concreto (horario del negocio); el resto de /settings
// sigue bloqueado porque contiene datos sensibles.
{http.MethodGet, regexp.MustCompile(`^/ea-api/v1/settings/company_working_plan/?$`)},
}
func eaRouteAllowed(method, path string) bool {
@@ -174,6 +177,7 @@ type eaAppointment struct {
type bookRequest struct {
Nombre string `json:"nombre"`
Apellidos string `json:"apellidos"`
Email string `json:"email"`
Telefono string `json:"telefono"`
Mensaje string `json:"mensaje"`
@@ -206,11 +210,12 @@ func handleBook(ea *eaClient) http.HandlerFunc {
return
}
req.Nombre = strings.TrimSpace(req.Nombre)
req.Apellidos = strings.TrimSpace(req.Apellidos)
req.Email = strings.TrimSpace(req.Email)
req.Telefono = strings.TrimSpace(req.Telefono)
req.Mensaje = strings.TrimSpace(req.Mensaje)
if req.Nombre == "" || req.Email == "" || req.Telefono == "" ||
if req.Nombre == "" || req.Apellidos == "" || req.Email == "" || req.Telefono == "" ||
len(req.ServiceIDs) == 0 || req.ProviderID <= 0 ||
!reDate.MatchString(req.Date) || !reTime.MatchString(req.Time) {
writeJSONError(w, http.StatusBadRequest, "datos_incompletos")
@@ -268,7 +273,7 @@ func handleBook(ea *eaClient) http.HandlerFunc {
names[i] = s.Name
}
notesLines := []string{
"Nombre: " + req.Nombre,
"Nombre: " + req.Nombre + " " + req.Apellidos,
"Email: " + req.Email,
"Teléfono: " + req.Telefono,
"Servicios: " + strings.Join(names, " + "),
@@ -320,11 +325,10 @@ func (c *eaClient) findOrCreateCustomer(req bookRequest) (int, error) {
}
}
first, last := splitName(req.Nombre)
var created eaCustomer
body := eaCustomer{
FirstName: first,
LastName: last,
FirstName: req.Nombre,
LastName: req.Apellidos,
Email: req.Email,
Phone: req.Telefono,
Notes: "Creado desde web MAY Studio",
@@ -338,18 +342,6 @@ func (c *eaClient) findOrCreateCustomer(req bookRequest) (int, error) {
return int(created.ID), nil
}
func splitName(full string) (first, last string) {
parts := strings.Fields(full)
switch len(parts) {
case 0:
return full, ""
case 1:
return parts[0], ""
default:
return parts[0], strings.Join(parts[1:], " ")
}
}
func main() {
port := flag.Int("port", 8080, "puerto del servidor")
flag.Parse()