feat: migrar backend unificado a Go 1.27 + SPA Vite embebido
This commit is contained in:
@@ -0,0 +1,979 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"cotizador/internal/audit"
|
||||
"cotizador/internal/auth"
|
||||
"cotizador/internal/db"
|
||||
"cotizador/internal/excel"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func (s *Server) queryServicioCatalogo(ctx context.Context, whereSQL string, args ...any) ([]map[string]any, error) {
|
||||
rows, err := s.Pool.Query(ctx, `
|
||||
SELECT sc."id", sc."nombre", sc."descripcion", sc."fase", sc."tipoPago", sc."precioBase",
|
||||
sc."tiempoEntrega", sc."entregablesDefault", sc."categoriaId", sc."variante", sc."nivel",
|
||||
sc."activo", sc."soloAdmin", sc."orden",
|
||||
c."nombre", c."color",
|
||||
(SELECT COUNT(*) FROM "ServicioCotizado" cot WHERE cot."servicioCatalogoId" = sc."id") AS en_cotizaciones
|
||||
FROM "ServicioCatalogo" sc
|
||||
LEFT JOIN "Categoria" c ON c."id" = sc."categoriaId"
|
||||
WHERE `+whereSQL+`
|
||||
ORDER BY sc."fase" ASC, sc."orden" ASC, sc."nombre" ASC
|
||||
`, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
out := []map[string]any{}
|
||||
for rows.Next() {
|
||||
var id, nombre, tipoPago, tiempoEntrega string
|
||||
var descripcion, categoriaID, variante, nivel, catNombre, catColor *string
|
||||
var fase, orden, enCot int
|
||||
var precioBase float64
|
||||
var entregablesRaw []byte
|
||||
var activo, soloAdmin bool
|
||||
if err := rows.Scan(
|
||||
&id, &nombre, &descripcion, &fase, &tipoPago, &precioBase,
|
||||
&tiempoEntrega, &entregablesRaw, &categoriaID, &variante, &nivel,
|
||||
&activo, &soloAdmin, &orden,
|
||||
&catNombre, &catColor, &enCot,
|
||||
); err != nil {
|
||||
continue
|
||||
}
|
||||
var entregables []string
|
||||
_ = json.Unmarshal(entregablesRaw, &entregables)
|
||||
if entregables == nil {
|
||||
entregables = []string{}
|
||||
}
|
||||
var catRel any
|
||||
if categoriaID != nil && catNombre != nil {
|
||||
catRel = map[string]any{"id": *categoriaID, "nombre": *catNombre, "color": catColor}
|
||||
}
|
||||
out = append(out, map[string]any{
|
||||
"id": id,
|
||||
"nombre": nombre,
|
||||
"descripcion": descripcion,
|
||||
"fase": fase,
|
||||
"tipoPago": tipoPago,
|
||||
"precioBase": precioBase,
|
||||
"tiempoEntrega": tiempoEntrega,
|
||||
"entregablesDefault": entregables,
|
||||
"categoriaId": categoriaID,
|
||||
"categoriaNombre": catNombre,
|
||||
"categoriaColor": catColor,
|
||||
"categoriaRel": catRel,
|
||||
"variante": variante,
|
||||
"nivel": nivel,
|
||||
"activo": activo,
|
||||
"soloAdmin": soloAdmin,
|
||||
"orden": orden,
|
||||
"enCotizaciones": enCot,
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *Server) handleCatalogoList(w http.ResponseWriter, r *http.Request) {
|
||||
actor, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{Scopes: []string{"catalogo:leer"}, RecursoTipo: "catalogo"})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
q := r.URL.Query()
|
||||
conds := []string{"1=1"}
|
||||
args := []any{}
|
||||
add := func(v any) string {
|
||||
args = append(args, v)
|
||||
return fmt.Sprintf("$%d", len(args))
|
||||
}
|
||||
|
||||
if actor.IsAgent() {
|
||||
conds = append(conds, `sc."soloAdmin" = false`)
|
||||
}
|
||||
if v := strings.TrimSpace(q.Get("q")); v != "" {
|
||||
p := add("%" + v + "%")
|
||||
conds = append(conds, fmt.Sprintf(`(sc."nombre" ILIKE %s OR COALESCE(sc."descripcion", '') ILIKE %s OR COALESCE(sc."variante", '') ILIKE %s)`, p, p, p))
|
||||
}
|
||||
if v := strings.TrimSpace(q.Get("fase")); v != "" {
|
||||
if f, err := strconv.Atoi(v); err == nil {
|
||||
conds = append(conds, `sc."fase" = `+add(f))
|
||||
}
|
||||
}
|
||||
if v := strings.TrimSpace(q.Get("tipoPago")); v != "" {
|
||||
conds = append(conds, `sc."tipoPago" = `+add(v))
|
||||
}
|
||||
if v := strings.TrimSpace(q.Get("categoriaId")); v != "" {
|
||||
conds = append(conds, `sc."categoriaId" = `+add(v))
|
||||
}
|
||||
if v := strings.TrimSpace(q.Get("activo")); v == "true" || v == "false" {
|
||||
conds = append(conds, `sc."activo" = `+add(v == "true"))
|
||||
}
|
||||
|
||||
list, err := s.queryServicioCatalogo(r.Context(), strings.Join(conds, " AND "), args...)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error listando catalogo")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, list)
|
||||
}
|
||||
|
||||
func (s *Server) handleCatalogoGet(w http.ResponseWriter, r *http.Request) {
|
||||
actor, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{Scopes: []string{"catalogo:leer"}, RecursoTipo: "catalogo"})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
list, err := s.queryServicioCatalogo(r.Context(), `sc."id" = $1`, id)
|
||||
if err != nil || len(list) == 0 {
|
||||
writeError(w, http.StatusNotFound, "Servicio no encontrado")
|
||||
return
|
||||
}
|
||||
svc := list[0]
|
||||
if actor.IsAgent() && svc["soloAdmin"] == true {
|
||||
tipo, aid, anom := actor.AuditActor()
|
||||
audit.Registrar(r.Context(), s.Pool, audit.Entry{
|
||||
ActorTipo: tipo, ActorID: aid, ActorNombre: anom,
|
||||
Accion: "catalogo.solo_admin_bloqueado", RecursoTipo: "catalogo", RecursoID: id,
|
||||
IP: audit.ClientIP(r), RequestID: audit.RequestID(r), Exito: false,
|
||||
})
|
||||
writeError(w, http.StatusForbidden, "Servicio restringido para administradores")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, svc)
|
||||
}
|
||||
|
||||
func (s *Server) handleCatalogoCreate(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "catalogo"}); !ok {
|
||||
return
|
||||
}
|
||||
var raw map[string]any
|
||||
if err := decodeJSON(r, &raw); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "JSON invalido")
|
||||
return
|
||||
}
|
||||
|
||||
var detalles []ValidationDetail
|
||||
nombre := strings.TrimSpace(asString(raw["nombre"]))
|
||||
if nombre == "" {
|
||||
detalles = append(detalles, ValidationDetail{Campo: "nombre", Mensaje: "El nombre es obligatorio"})
|
||||
}
|
||||
fase, faseOK := asInt(raw["fase"])
|
||||
if !faseOK || fase < 0 || fase > 3 {
|
||||
detalles = append(detalles, ValidationDetail{Campo: "fase", Mensaje: "La fase debe ser 0, 1, 2 o 3"})
|
||||
}
|
||||
tipoPago := strings.TrimSpace(asString(raw["tipoPago"]))
|
||||
if tipoPago != "unico" && tipoPago != "mensual" {
|
||||
detalles = append(detalles, ValidationDetail{Campo: "tipoPago", Mensaje: "tipoPago debe ser unico o mensual"})
|
||||
}
|
||||
precioBase, precioOK := asFloat(raw["precioBase"])
|
||||
if !precioOK || precioBase < 0 {
|
||||
detalles = append(detalles, ValidationDetail{Campo: "precioBase", Mensaje: "precioBase debe ser >= 0"})
|
||||
}
|
||||
if len(detalles) > 0 {
|
||||
writeValidationError(w, detalles)
|
||||
return
|
||||
}
|
||||
|
||||
var categoriaID *string
|
||||
if cid := strings.TrimSpace(asString(raw["categoriaId"])); cid != "" {
|
||||
var exists bool
|
||||
_ = s.Pool.QueryRow(r.Context(), `SELECT EXISTS(SELECT 1 FROM "Categoria" WHERE "id" = $1)`, cid).Scan(&exists)
|
||||
if !exists {
|
||||
writeValidationError(w, []ValidationDetail{{Campo: "categoriaId", Mensaje: "La categoria no existe"}})
|
||||
return
|
||||
}
|
||||
categoriaID = &cid
|
||||
}
|
||||
|
||||
orden, hasOrden := asInt(raw["orden"])
|
||||
if !hasOrden {
|
||||
var maxOrden int
|
||||
_ = s.Pool.QueryRow(r.Context(), `SELECT COALESCE(MAX("orden"), 0) FROM "ServicioCatalogo" WHERE "fase" = $1`, fase).Scan(&maxOrden)
|
||||
orden = maxOrden + 1
|
||||
}
|
||||
|
||||
tiempoEntrega := firstNonEmptyStr(asString(raw["tiempoEntrega"]), "4 - 10 dias")
|
||||
entregables := asStringSlice(raw["entregablesDefault"])
|
||||
entJSON, _ := json.Marshal(entregables)
|
||||
|
||||
activo := true
|
||||
if v, ok := raw["activo"].(bool); ok {
|
||||
activo = v
|
||||
}
|
||||
soloAdmin := false
|
||||
if v, ok := raw["soloAdmin"].(bool); ok {
|
||||
soloAdmin = v
|
||||
}
|
||||
|
||||
id := db.NewID()
|
||||
_, err := s.Pool.Exec(r.Context(), `
|
||||
INSERT INTO "ServicioCatalogo" (
|
||||
"id", "nombre", "descripcion", "fase", "tipoPago", "precioBase",
|
||||
"tiempoEntrega", "entregablesDefault", "categoriaId", "variante", "nivel",
|
||||
"activo", "soloAdmin", "orden", "createdAt", "updatedAt"
|
||||
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,NOW(),NOW())
|
||||
`, id, nombre, nullableTrim(asString(raw["descripcion"])), fase, tipoPago, precioBase,
|
||||
tiempoEntrega, entJSON, categoriaID, nullableTrim(asString(raw["variante"])), nullableTrim(asString(raw["nivel"])),
|
||||
activo, soloAdmin, orden)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error creando servicio")
|
||||
return
|
||||
}
|
||||
|
||||
list, _ := s.queryServicioCatalogo(r.Context(), `sc."id" = $1`, id)
|
||||
if len(list) == 1 {
|
||||
writeJSON(w, http.StatusCreated, list[0])
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusCreated, map[string]any{"id": id})
|
||||
}
|
||||
|
||||
func (s *Server) handleCatalogoPatch(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "catalogo"}); !ok {
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
var exists bool
|
||||
_ = s.Pool.QueryRow(r.Context(), `SELECT EXISTS(SELECT 1 FROM "ServicioCatalogo" WHERE "id" = $1)`, id).Scan(&exists)
|
||||
if !exists {
|
||||
writeError(w, http.StatusNotFound, "Servicio no encontrado")
|
||||
return
|
||||
}
|
||||
|
||||
var raw map[string]any
|
||||
if err := decodeJSON(r, &raw); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "JSON invalido")
|
||||
return
|
||||
}
|
||||
|
||||
sets := []string{`"updatedAt" = NOW()`}
|
||||
args := []any{}
|
||||
add := func(col string, val any) {
|
||||
args = append(args, val)
|
||||
sets = append(sets, fmt.Sprintf(`"%s" = $%d`, col, len(args)))
|
||||
}
|
||||
|
||||
if v, ok := raw["nombre"]; ok {
|
||||
nom := strings.TrimSpace(asString(v))
|
||||
if nom == "" {
|
||||
writeValidationError(w, []ValidationDetail{{Campo: "nombre", Mensaje: "El nombre no puede estar vacio"}})
|
||||
return
|
||||
}
|
||||
add("nombre", nom)
|
||||
}
|
||||
if v, ok := raw["descripcion"]; ok {
|
||||
add("descripcion", nullableTrim(asString(v)))
|
||||
}
|
||||
if v, ok := raw["fase"]; ok {
|
||||
f, okInt := asInt(v)
|
||||
if !okInt || f < 0 || f > 3 {
|
||||
writeValidationError(w, []ValidationDetail{{Campo: "fase", Mensaje: "Fase invalida"}})
|
||||
return
|
||||
}
|
||||
add("fase", f)
|
||||
}
|
||||
if v, ok := raw["tipoPago"]; ok {
|
||||
tp := strings.TrimSpace(asString(v))
|
||||
if tp != "unico" && tp != "mensual" {
|
||||
writeValidationError(w, []ValidationDetail{{Campo: "tipoPago", Mensaje: "tipoPago invalido"}})
|
||||
return
|
||||
}
|
||||
add("tipoPago", tp)
|
||||
}
|
||||
if v, ok := raw["precioBase"]; ok {
|
||||
pb, okF := asFloat(v)
|
||||
if !okF || pb < 0 {
|
||||
writeValidationError(w, []ValidationDetail{{Campo: "precioBase", Mensaje: "precioBase invalido"}})
|
||||
return
|
||||
}
|
||||
add("precioBase", pb)
|
||||
}
|
||||
if v, ok := raw["tiempoEntrega"]; ok {
|
||||
add("tiempoEntrega", firstNonEmptyStr(asString(v), "4 - 10 dias"))
|
||||
}
|
||||
if v, ok := raw["entregablesDefault"]; ok {
|
||||
entJSON, _ := json.Marshal(asStringSlice(v))
|
||||
add("entregablesDefault", entJSON)
|
||||
}
|
||||
if v, ok := raw["categoriaId"]; ok {
|
||||
cid := strings.TrimSpace(asString(v))
|
||||
if cid == "" {
|
||||
add("categoriaId", nil)
|
||||
} else {
|
||||
var catOK bool
|
||||
_ = s.Pool.QueryRow(r.Context(), `SELECT EXISTS(SELECT 1 FROM "Categoria" WHERE "id" = $1)`, cid).Scan(&catOK)
|
||||
if !catOK {
|
||||
writeValidationError(w, []ValidationDetail{{Campo: "categoriaId", Mensaje: "La categoria no existe"}})
|
||||
return
|
||||
}
|
||||
add("categoriaId", cid)
|
||||
}
|
||||
}
|
||||
if v, ok := raw["variante"]; ok {
|
||||
add("variante", nullableTrim(asString(v)))
|
||||
}
|
||||
if v, ok := raw["nivel"]; ok {
|
||||
add("nivel", nullableTrim(asString(v)))
|
||||
}
|
||||
if v, ok := raw["activo"].(bool); ok {
|
||||
add("activo", v)
|
||||
}
|
||||
if v, ok := raw["soloAdmin"].(bool); ok {
|
||||
add("soloAdmin", v)
|
||||
}
|
||||
if v, ok := raw["orden"]; ok {
|
||||
if ord, okInt := asInt(v); okInt {
|
||||
add("orden", ord)
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, id)
|
||||
_, err := s.Pool.Exec(r.Context(), fmt.Sprintf(`UPDATE "ServicioCatalogo" SET %s WHERE "id" = $%d`, strings.Join(sets, ", "), len(args)), args...)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error actualizando servicio")
|
||||
return
|
||||
}
|
||||
|
||||
list, _ := s.queryServicioCatalogo(r.Context(), `sc."id" = $1`, id)
|
||||
if len(list) == 1 {
|
||||
writeJSON(w, http.StatusOK, list[0])
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"id": id})
|
||||
}
|
||||
|
||||
func (s *Server) handleCatalogoDelete(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "catalogo"}); !ok {
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
var enCot int
|
||||
if err := s.Pool.QueryRow(r.Context(), `SELECT COUNT(*) FROM "ServicioCotizado" WHERE "servicioCatalogoId" = $1`, id).Scan(&enCot); err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error verificando uso del servicio")
|
||||
return
|
||||
}
|
||||
if enCot > 0 {
|
||||
tag, err := s.Pool.Exec(r.Context(), `UPDATE "ServicioCatalogo" SET "activo" = false, "updatedAt" = NOW() WHERE "id" = $1`, id)
|
||||
if err != nil || tag.RowsAffected() == 0 {
|
||||
writeError(w, http.StatusNotFound, "Servicio no encontrado")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "archivado": true, "enCotizaciones": enCot})
|
||||
return
|
||||
}
|
||||
tag, err := s.Pool.Exec(r.Context(), `DELETE FROM "ServicioCatalogo" WHERE "id" = $1`, id)
|
||||
if err != nil || tag.RowsAffected() == 0 {
|
||||
writeError(w, http.StatusNotFound, "Servicio no encontrado")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "eliminado": true})
|
||||
}
|
||||
|
||||
func (s *Server) handleCategoriasList(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{Scopes: []string{"catalogo:leer"}, RecursoTipo: "categoria"}); !ok {
|
||||
return
|
||||
}
|
||||
rows, err := s.Pool.Query(r.Context(), `
|
||||
SELECT c."id", c."nombre", c."descripcion", c."color", c."activo", c."orden",
|
||||
(SELECT COUNT(*) FROM "ServicioCatalogo" sc WHERE sc."categoriaId" = c."id") AS servicios_count
|
||||
FROM "Categoria" c
|
||||
ORDER BY c."orden" ASC, c."nombre" ASC
|
||||
`)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error listando categorias")
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
list := []map[string]any{}
|
||||
for rows.Next() {
|
||||
var id, nombre, color string
|
||||
var desc *string
|
||||
var activo bool
|
||||
var orden, cnt int
|
||||
if rows.Scan(&id, &nombre, &desc, &color, &activo, &orden, &cnt) == nil {
|
||||
list = append(list, map[string]any{
|
||||
"id": id, "nombre": nombre, "descripcion": desc, "color": color, "activo": activo, "orden": orden,
|
||||
"_count": map[string]any{"servicios": cnt},
|
||||
})
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, list)
|
||||
}
|
||||
|
||||
func (s *Server) handleCategoriasCreate(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "categoria"}); !ok {
|
||||
return
|
||||
}
|
||||
var body struct {
|
||||
Nombre string `json:"nombre"`
|
||||
Descripcion *string `json:"descripcion"`
|
||||
Color string `json:"color"`
|
||||
Orden *int `json:"orden"`
|
||||
}
|
||||
if err := decodeJSON(r, &body); err != nil || strings.TrimSpace(body.Nombre) == "" {
|
||||
writeError(w, http.StatusBadRequest, "El nombre es obligatorio")
|
||||
return
|
||||
}
|
||||
color := firstNonEmptyStr(body.Color, "#6b7280")
|
||||
orden := 0
|
||||
if body.Orden != nil {
|
||||
orden = *body.Orden
|
||||
} else {
|
||||
_ = s.Pool.QueryRow(r.Context(), `SELECT COALESCE(MAX("orden"), 0) + 1 FROM "Categoria"`).Scan(&orden)
|
||||
}
|
||||
id := db.NewID()
|
||||
_, err := s.Pool.Exec(r.Context(), `
|
||||
INSERT INTO "Categoria" ("id", "nombre", "descripcion", "color", "activo", "orden", "createdAt", "updatedAt")
|
||||
VALUES ($1, $2, $3, $4, true, $5, NOW(), NOW())
|
||||
`, id, strings.TrimSpace(body.Nombre), body.Descripcion, color, orden)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "23505") {
|
||||
writeError(w, http.StatusConflict, "Ya existe una categoria con ese nombre")
|
||||
return
|
||||
}
|
||||
writeError(w, http.StatusInternalServerError, "Error creando categoria")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusCreated, map[string]any{
|
||||
"id": id, "nombre": strings.TrimSpace(body.Nombre), "descripcion": body.Descripcion, "color": color, "activo": true, "orden": orden,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleCategoriasUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "categoria"}); !ok {
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
var body struct {
|
||||
Nombre *string `json:"nombre"`
|
||||
Descripcion *string `json:"descripcion"`
|
||||
Color *string `json:"color"`
|
||||
Activo *bool `json:"activo"`
|
||||
Orden *int `json:"orden"`
|
||||
}
|
||||
if err := decodeJSON(r, &body); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "JSON invalido")
|
||||
return
|
||||
}
|
||||
sets := []string{`"updatedAt" = NOW()`}
|
||||
args := []any{}
|
||||
add := func(col string, val any) {
|
||||
args = append(args, val)
|
||||
sets = append(sets, fmt.Sprintf(`"%s" = $%d`, col, len(args)))
|
||||
}
|
||||
if body.Nombre != nil {
|
||||
add("nombre", strings.TrimSpace(*body.Nombre))
|
||||
}
|
||||
if body.Descripcion != nil {
|
||||
add("descripcion", *body.Descripcion)
|
||||
}
|
||||
if body.Color != nil {
|
||||
add("color", *body.Color)
|
||||
}
|
||||
if body.Activo != nil {
|
||||
add("activo", *body.Activo)
|
||||
}
|
||||
if body.Orden != nil {
|
||||
add("orden", *body.Orden)
|
||||
}
|
||||
args = append(args, id)
|
||||
var nombre, color string
|
||||
var desc *string
|
||||
var activo bool
|
||||
var orden int
|
||||
err := s.Pool.QueryRow(r.Context(), fmt.Sprintf(`
|
||||
UPDATE "Categoria" SET %s WHERE "id" = $%d
|
||||
RETURNING "nombre", "descripcion", "color", "activo", "orden"
|
||||
`, strings.Join(sets, ", "), len(args)), args...).Scan(&nombre, &desc, &color, &activo, &orden)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
writeError(w, http.StatusNotFound, "Categoria no encontrada")
|
||||
return
|
||||
}
|
||||
writeError(w, http.StatusInternalServerError, "Error actualizando categoria")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"id": id, "nombre": nombre, "descripcion": desc, "color": color, "activo": activo, "orden": orden})
|
||||
}
|
||||
|
||||
func (s *Server) handleCategoriasDelete(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "categoria"}); !ok {
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
var cnt int
|
||||
_ = s.Pool.QueryRow(r.Context(), `SELECT COUNT(*) FROM "ServicioCatalogo" WHERE "categoriaId" = $1`, id).Scan(&cnt)
|
||||
if cnt > 0 {
|
||||
writeError(w, http.StatusConflict, "No se puede eliminar una categoria con servicios asociados")
|
||||
return
|
||||
}
|
||||
tag, err := s.Pool.Exec(r.Context(), `DELETE FROM "Categoria" WHERE "id" = $1`, id)
|
||||
if err != nil || tag.RowsAffected() == 0 {
|
||||
writeError(w, http.StatusNotFound, "Categoria no encontrada")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
func (s *Server) loadPaqueteFull(ctx context.Context, paqueteID string, hideSoloAdmin bool) (map[string]any, error) {
|
||||
var id, nombre string
|
||||
var desc *string
|
||||
var activo bool
|
||||
err := s.Pool.QueryRow(ctx, `SELECT "id", "nombre", "descripcion", "activo" FROM "Paquete" WHERE "id" = $1`, paqueteID).Scan(&id, &nombre, &desc, &activo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
faseRows, err := s.Pool.Query(ctx, `SELECT "id", "nombre", "orden" FROM "FasePaquete" WHERE "paqueteId" = $1 ORDER BY "orden" ASC`, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer faseRows.Close()
|
||||
|
||||
fases := []map[string]any{}
|
||||
for faseRows.Next() {
|
||||
var fid, fnom string
|
||||
var forden int
|
||||
if faseRows.Scan(&fid, &fnom, &forden) != nil {
|
||||
continue
|
||||
}
|
||||
filterAdmin := ""
|
||||
if hideSoloAdmin {
|
||||
filterAdmin = ` AND sc."soloAdmin" = false`
|
||||
}
|
||||
sRows, _ := s.Pool.Query(ctx, `
|
||||
SELECT sp."id", sp."servicioCatalogoId", sc."nombre", sc."descripcion", sc."fase", sc."tipoPago",
|
||||
sc."precioBase", sc."tiempoEntrega", sc."entregablesDefault", sc."categoriaId", sc."variante", sc."nivel", sc."soloAdmin",
|
||||
c."nombre", c."color"
|
||||
FROM "ServicioPaquete" sp
|
||||
JOIN "ServicioCatalogo" sc ON sc."id" = sp."servicioCatalogoId"
|
||||
LEFT JOIN "Categoria" c ON c."id" = sc."categoriaId"
|
||||
WHERE sp."fasePaqueteId" = $1 AND sc."activo" = true`+filterAdmin+`
|
||||
ORDER BY sc."orden" ASC, sc."nombre" ASC
|
||||
`, fid)
|
||||
svcs := []map[string]any{}
|
||||
if sRows != nil {
|
||||
for sRows.Next() {
|
||||
var spid, scid, snom, tp, te string
|
||||
var sdesc, cid, vari, niv, cnom, ccol *string
|
||||
var sfase int
|
||||
var pb float64
|
||||
var entRaw []byte
|
||||
var sadmin bool
|
||||
if sRows.Scan(&spid, &scid, &snom, &sdesc, &sfase, &tp, &pb, &te, &entRaw, &cid, &vari, &niv, &sadmin, &cnom, &ccol) == nil {
|
||||
var ent []string
|
||||
_ = json.Unmarshal(entRaw, &ent)
|
||||
if ent == nil {
|
||||
ent = []string{}
|
||||
}
|
||||
svcs = append(svcs, map[string]any{
|
||||
"id": spid,
|
||||
"servicioCatalogoId": scid,
|
||||
"fasePaqueteId": fid,
|
||||
"servicio": map[string]any{
|
||||
"id": scid, "nombre": snom, "descripcion": sdesc, "fase": sfase,
|
||||
"tipoPago": tp, "precioBase": pb, "tiempoEntrega": te,
|
||||
"entregablesDefault": ent, "categoriaId": cid, "variante": vari, "nivel": niv,
|
||||
"soloAdmin": sadmin, "categoriaNombre": cnom, "categoriaColor": ccol,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
sRows.Close()
|
||||
}
|
||||
fases = append(fases, map[string]any{
|
||||
"id": fid, "paqueteId": id, "nombre": fnom, "orden": forden, "servicios": svcs,
|
||||
})
|
||||
}
|
||||
return map[string]any{
|
||||
"id": id, "nombre": nombre, "descripcion": desc, "activo": activo, "fases": fases,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) handlePaquetesList(w http.ResponseWriter, r *http.Request) {
|
||||
actor, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{Scopes: []string{"catalogo:leer"}, RecursoTipo: "paquete"})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
rows, err := s.Pool.Query(r.Context(), `SELECT "id" FROM "Paquete" WHERE "activo" = true ORDER BY "createdAt" ASC`)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error listando paquetes")
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
var ids []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if rows.Scan(&id) == nil {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
list := []map[string]any{}
|
||||
for _, id := range ids {
|
||||
if p, err := s.loadPaqueteFull(r.Context(), id, actor.IsAgent()); err == nil {
|
||||
list = append(list, p)
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, list)
|
||||
}
|
||||
|
||||
func (s *Server) handlePaquetesGet(w http.ResponseWriter, r *http.Request) {
|
||||
actor, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{Scopes: []string{"catalogo:leer"}, RecursoTipo: "paquete"})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
p, err := s.loadPaqueteFull(r.Context(), id, actor.IsAgent())
|
||||
if err != nil {
|
||||
writeError(w, http.StatusNotFound, "Paquete no encontrado")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, p)
|
||||
}
|
||||
|
||||
func (s *Server) handlePaquetesCreate(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "paquete"}); !ok {
|
||||
return
|
||||
}
|
||||
var body struct {
|
||||
Nombre string `json:"nombre"`
|
||||
Descripcion *string `json:"descripcion"`
|
||||
Fases []struct {
|
||||
Nombre string `json:"nombre"`
|
||||
Orden int `json:"orden"`
|
||||
} `json:"fases"`
|
||||
}
|
||||
if err := decodeJSON(r, &body); err != nil || strings.TrimSpace(body.Nombre) == "" {
|
||||
writeError(w, http.StatusBadRequest, "El nombre del paquete es obligatorio")
|
||||
return
|
||||
}
|
||||
id := db.NewID()
|
||||
_, err := s.Pool.Exec(r.Context(), `
|
||||
INSERT INTO "Paquete" ("id", "nombre", "descripcion", "activo", "createdAt", "updatedAt")
|
||||
VALUES ($1, $2, $3, true, NOW(), NOW())
|
||||
`, id, strings.TrimSpace(body.Nombre), body.Descripcion)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error creando paquete")
|
||||
return
|
||||
}
|
||||
for i, f := range body.Fases {
|
||||
ord := f.Orden
|
||||
if ord == 0 {
|
||||
ord = i
|
||||
}
|
||||
_, _ = s.Pool.Exec(r.Context(), `
|
||||
INSERT INTO "FasePaquete" ("id", "paqueteId", "nombre", "orden", "createdAt", "updatedAt")
|
||||
VALUES ($1, $2, $3, $4, NOW(), NOW())
|
||||
`, db.NewID(), id, strings.TrimSpace(f.Nombre), ord)
|
||||
}
|
||||
p, _ := s.loadPaqueteFull(r.Context(), id, false)
|
||||
writeJSON(w, http.StatusCreated, p)
|
||||
}
|
||||
|
||||
func (s *Server) handlePaquetesUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "paquete"}); !ok {
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
var body struct {
|
||||
Nombre *string `json:"nombre"`
|
||||
Descripcion *string `json:"descripcion"`
|
||||
Activo *bool `json:"activo"`
|
||||
}
|
||||
if err := decodeJSON(r, &body); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "JSON invalido")
|
||||
return
|
||||
}
|
||||
sets := []string{`"updatedAt" = NOW()`}
|
||||
args := []any{}
|
||||
add := func(col string, val any) {
|
||||
args = append(args, val)
|
||||
sets = append(sets, fmt.Sprintf(`"%s" = $%d`, col, len(args)))
|
||||
}
|
||||
if body.Nombre != nil {
|
||||
add("nombre", strings.TrimSpace(*body.Nombre))
|
||||
}
|
||||
if body.Descripcion != nil {
|
||||
add("descripcion", *body.Descripcion)
|
||||
}
|
||||
if body.Activo != nil {
|
||||
add("activo", *body.Activo)
|
||||
}
|
||||
args = append(args, id)
|
||||
tag, err := s.Pool.Exec(r.Context(), fmt.Sprintf(`UPDATE "Paquete" SET %s WHERE "id" = $%d`, strings.Join(sets, ", "), len(args)), args...)
|
||||
if err != nil || tag.RowsAffected() == 0 {
|
||||
writeError(w, http.StatusNotFound, "Paquete no encontrado")
|
||||
return
|
||||
}
|
||||
p, _ := s.loadPaqueteFull(r.Context(), id, false)
|
||||
writeJSON(w, http.StatusOK, p)
|
||||
}
|
||||
|
||||
func (s *Server) handlePaquetesDelete(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "paquete"}); !ok {
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
tag, err := s.Pool.Exec(r.Context(), `DELETE FROM "Paquete" WHERE "id" = $1`, id)
|
||||
if err != nil || tag.RowsAffected() == 0 {
|
||||
writeError(w, http.StatusNotFound, "Paquete no encontrado")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
func (s *Server) handlePaquetesManage(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "paquete"}); !ok {
|
||||
return
|
||||
}
|
||||
paqueteID := chi.URLParam(r, "id")
|
||||
var body struct {
|
||||
Action string `json:"action"`
|
||||
FaseID string `json:"faseId"`
|
||||
FasePaqueteID string `json:"fasePaqueteId"`
|
||||
Nombre string `json:"nombre"`
|
||||
Orden *int `json:"orden"`
|
||||
ServicioCatalogoID string `json:"servicioCatalogoId"`
|
||||
}
|
||||
if err := decodeJSON(r, &body); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "JSON invalido")
|
||||
return
|
||||
}
|
||||
fid := firstNonEmptyStr(body.FasePaqueteID, body.FaseID)
|
||||
|
||||
switch body.Action {
|
||||
case "addFase":
|
||||
ord := 0
|
||||
if body.Orden != nil {
|
||||
ord = *body.Orden
|
||||
} else {
|
||||
_ = s.Pool.QueryRow(r.Context(), `SELECT COALESCE(MAX("orden"), -1) + 1 FROM "FasePaquete" WHERE "paqueteId" = $1`, paqueteID).Scan(&ord)
|
||||
}
|
||||
_, err := s.Pool.Exec(r.Context(), `
|
||||
INSERT INTO "FasePaquete" ("id", "paqueteId", "nombre", "orden", "createdAt", "updatedAt")
|
||||
VALUES ($1, $2, $3, $4, NOW(), NOW())
|
||||
`, db.NewID(), paqueteID, strings.TrimSpace(body.Nombre), ord)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error agregando fase")
|
||||
return
|
||||
}
|
||||
case "updateFase":
|
||||
if body.Nombre != "" {
|
||||
_, _ = s.Pool.Exec(r.Context(), `UPDATE "FasePaquete" SET "nombre" = $1, "updatedAt" = NOW() WHERE "id" = $2`, strings.TrimSpace(body.Nombre), fid)
|
||||
}
|
||||
if body.Orden != nil {
|
||||
_, _ = s.Pool.Exec(r.Context(), `UPDATE "FasePaquete" SET "orden" = $1, "updatedAt" = NOW() WHERE "id" = $2`, *body.Orden, fid)
|
||||
}
|
||||
case "deleteFase":
|
||||
_, _ = s.Pool.Exec(r.Context(), `DELETE FROM "FasePaquete" WHERE "id" = $1`, fid)
|
||||
case "addServicio":
|
||||
_, _ = s.Pool.Exec(r.Context(), `
|
||||
INSERT INTO "ServicioPaquete" ("id", "servicioCatalogoId", "fasePaqueteId", "createdAt", "updatedAt")
|
||||
VALUES ($1, $2, $3, NOW(), NOW())
|
||||
ON CONFLICT ("servicioCatalogoId", "fasePaqueteId") DO NOTHING
|
||||
`, db.NewID(), body.ServicioCatalogoID, fid)
|
||||
case "removeServicio":
|
||||
_, _ = s.Pool.Exec(r.Context(), `
|
||||
DELETE FROM "ServicioPaquete" WHERE "servicioCatalogoId" = $1 AND "fasePaqueteId" = $2
|
||||
`, body.ServicioCatalogoID, fid)
|
||||
default:
|
||||
writeError(w, http.StatusBadRequest, "Accion invalida")
|
||||
return
|
||||
}
|
||||
|
||||
p, err := s.loadPaqueteFull(r.Context(), paqueteID, false)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusNotFound, "Paquete no encontrado")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, p)
|
||||
}
|
||||
|
||||
func (s *Server) handleExportCatalogoCSV(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "catalogo"}); !ok {
|
||||
return
|
||||
}
|
||||
list, err := s.queryServicioCatalogo(r.Context(), `sc."activo" = true`)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error exportando catalogo")
|
||||
return
|
||||
}
|
||||
rows := make([]excel.CatalogoCSVRow, 0, len(list))
|
||||
for _, it := range list {
|
||||
cat := ""
|
||||
if c, ok := it["categoriaNombre"].(*string); ok && c != nil {
|
||||
cat = *c
|
||||
}
|
||||
vari := ""
|
||||
if v, ok := it["variante"].(*string); ok && v != nil {
|
||||
vari = *v
|
||||
}
|
||||
ent, _ := it["entregablesDefault"].([]string)
|
||||
rows = append(rows, excel.CatalogoCSVRow{
|
||||
Nombre: asString(it["nombre"]),
|
||||
Categoria: cat,
|
||||
Fase: it["fase"].(int),
|
||||
TipoPago: asString(it["tipoPago"]),
|
||||
PrecioBase: it["precioBase"].(float64),
|
||||
TiempoEntrega: asString(it["tiempoEntrega"]),
|
||||
Entregables: ent,
|
||||
Variante: vari,
|
||||
})
|
||||
}
|
||||
csvBytes, err := excel.ExportCatalogoCSV(rows)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Error generando CSV")
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/csv; charset=utf-8")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="catalogo-servicios.csv"`)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(csvBytes)
|
||||
}
|
||||
|
||||
func (s *Server) handleExportCatalogoPlantilla(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "catalogo"}); !ok {
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/csv; charset=utf-8")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="plantilla-catalogo.csv"`)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(excel.PlantillaCatalogoCSV())
|
||||
}
|
||||
|
||||
func (s *Server) handleImportCatalogoCSV(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := s.Auth.RequireActor(w, r, auth.RequireOptions{StaffOnly: true, RecursoTipo: "catalogo"}); !ok {
|
||||
return
|
||||
}
|
||||
if err := r.ParseMultipartForm(10 << 20); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "Error leyendo archivo multipart")
|
||||
return
|
||||
}
|
||||
file, _, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, "Se requiere el archivo en el campo 'file'")
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
raw, err := io.ReadAll(io.LimitReader(file, 10<<20))
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, "No se pudo leer el archivo")
|
||||
return
|
||||
}
|
||||
rows, err := excel.ParseCatalogoCSV(raw)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
catMap := map[string]string{}
|
||||
cRows, _ := s.Pool.Query(r.Context(), `SELECT "id", LOWER("nombre") FROM "Categoria" WHERE "activo" = true`)
|
||||
if cRows != nil {
|
||||
for cRows.Next() {
|
||||
var cid, cnom string
|
||||
if cRows.Scan(&cid, &cnom) == nil {
|
||||
catMap[cnom] = cid
|
||||
}
|
||||
}
|
||||
cRows.Close()
|
||||
}
|
||||
|
||||
imported := 0
|
||||
for i, row := range rows {
|
||||
var catID *string
|
||||
if id, ok := catMap[strings.ToLower(strings.TrimSpace(row.Categoria))]; ok {
|
||||
cid := id
|
||||
catID = &cid
|
||||
}
|
||||
entJSON, _ := json.Marshal(row.Entregables)
|
||||
_, err := s.Pool.Exec(r.Context(), `
|
||||
INSERT INTO "ServicioCatalogo" (
|
||||
"id", "nombre", "fase", "tipoPago", "precioBase", "tiempoEntrega",
|
||||
"entregablesDefault", "categoriaId", "variante", "activo", "soloAdmin", "orden", "createdAt", "updatedAt"
|
||||
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,true,false,$10,NOW(),NOW())
|
||||
`, db.NewID(), row.Nombre, row.Fase, row.TipoPago, row.PrecioBase, firstNonEmptyStr(row.TiempoEntrega, "4 - 10 dias"),
|
||||
entJSON, catID, nullableTrim(row.Variante), i+1)
|
||||
if err == nil {
|
||||
imported++
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "importados": imported})
|
||||
}
|
||||
|
||||
func asString(v any) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
s, ok := v.(string)
|
||||
if ok {
|
||||
return s
|
||||
}
|
||||
return fmt.Sprintf("%v", v)
|
||||
}
|
||||
|
||||
func nullableTrim(s string) *string {
|
||||
t := strings.TrimSpace(s)
|
||||
if t == "" {
|
||||
return nil
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func asInt(v any) (int, bool) {
|
||||
switch x := v.(type) {
|
||||
case float64:
|
||||
return int(x), true
|
||||
case int:
|
||||
return x, true
|
||||
case string:
|
||||
n, err := strconv.Atoi(strings.TrimSpace(x))
|
||||
return n, err == nil
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func asFloat(v any) (float64, bool) {
|
||||
switch x := v.(type) {
|
||||
case float64:
|
||||
return x, true
|
||||
case int:
|
||||
return float64(x), true
|
||||
case string:
|
||||
f, err := strconv.ParseFloat(strings.TrimSpace(x), 64)
|
||||
return f, err == nil
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func asStringSlice(v any) []string {
|
||||
if v == nil {
|
||||
return []string{}
|
||||
}
|
||||
switch arr := v.(type) {
|
||||
case []string:
|
||||
return arr
|
||||
case []any:
|
||||
out := make([]string, 0, len(arr))
|
||||
for _, item := range arr {
|
||||
if s := strings.TrimSpace(asString(item)); s != "" {
|
||||
out = append(out, s)
|
||||
}
|
||||
}
|
||||
return out
|
||||
default:
|
||||
return []string{}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user