fix: columna FK incorrecta en contrato_servidores y filtrado de BDs en modal
- syncContratoJoin derivaba "contrato_servidore_id" en vez de "servidor_id" al recortar el último carácter del nombre de tabla; ahora usa TrimPrefix+TrimSuffix para derivar correctamente servidor_id, conx_db_id, ai_config_id - Modal contratos: filteredConxDbList filtra BDs por servidor(es) seleccionado(s) en vez de mostrar todas las BDs sin contexto Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
62397f2f8c
commit
dfe8d9e4a9
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
@@ -155,8 +156,11 @@ func syncContratoJoin(db *gorm.DB, table string, contratoID uint, ids []uint) er
|
||||
if err := db.Exec("DELETE FROM "+table+" WHERE contrato_id = ?", contratoID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// Derive FK column: "contrato_servidores" → "servidor_id", "contrato_conx_dbs" → "conx_db_id"
|
||||
entityPlural := strings.TrimPrefix(table, "contrato_")
|
||||
fkCol := strings.TrimSuffix(entityPlural, "s") + "_id"
|
||||
for _, id := range ids {
|
||||
if err := db.Exec("INSERT INTO "+table+" (contrato_id, "+table[:len(table)-1]+"_id) VALUES (?, ?) ON CONFLICT DO NOTHING",
|
||||
if err := db.Exec("INSERT INTO "+table+" (contrato_id, "+fkCol+") VALUES (?, ?) ON CONFLICT DO NOTHING",
|
||||
contratoID, id,
|
||||
).Error; err != nil {
|
||||
return err
|
||||
|
||||
@@ -230,7 +230,7 @@
|
||||
<div class="col-span-2">
|
||||
<label class="text-xs font-medium text-gray-600 mb-1 block">Bases de datos <span class="font-normal text-gray-400">(filtradas por servidor seleccionado)</span></label>
|
||||
<div class="border rounded max-h-32 overflow-y-auto divide-y text-sm">
|
||||
<template x-for="db in conxDbList" :key="db.ID">
|
||||
<template x-for="db in filteredConxDbList" :key="db.ID">
|
||||
<label class="flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50 cursor-pointer">
|
||||
<input type="checkbox" :value="db.ID"
|
||||
:checked="form.conx_db_ids.includes(db.ID)"
|
||||
@@ -238,7 +238,7 @@
|
||||
<span x-text="db.nombre"></span>
|
||||
</label>
|
||||
</template>
|
||||
<div x-show="conxDbList.length===0" class="text-xs text-gray-400 px-3 py-2">
|
||||
<div x-show="filteredConxDbList.length===0" class="text-xs text-gray-400 px-3 py-2">
|
||||
<span x-text="form.servidor_ids.length > 0 ? 'Sin BD para los servidores seleccionados' : 'Selecciona un servidor primero'"></span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -476,6 +476,11 @@ document.addEventListener('alpine:init', () => {
|
||||
if (idx === -1) { this.form.ai_config_ids.push(id); } else { this.form.ai_config_ids.splice(idx, 1); }
|
||||
},
|
||||
|
||||
get filteredConxDbList() {
|
||||
if (!this.form.servidor_ids || this.form.servidor_ids.length === 0) return [];
|
||||
return this.conxDbList.filter(db => this.form.servidor_ids.includes(db.servidor_id));
|
||||
},
|
||||
|
||||
get precioSugerido() {
|
||||
return this.servicios
|
||||
.filter(s => (this.form.servicio_ids || []).includes(s.ID))
|
||||
|
||||
Reference in New Issue
Block a user