From a7339b8f14ebf2296379604248842f23d45f3cb7 Mon Sep 17 00:00:00 2001 From: Carlos Narro Date: Sat, 30 May 2026 19:41:04 +0200 Subject: [PATCH] =?UTF-8?q?Migrar=20resoluci=C3=B3n=20de=20tenant=20del=20?= =?UTF-8?q?panel=20a=20la=20sesi=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mvp/b2c/src/app/panel/actions.ts | 10 ++-------- mvp/b2c/src/db/pricing-queries.ts | 10 ++-------- mvp/b2c/src/db/queries.ts | 9 +-------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/mvp/b2c/src/app/panel/actions.ts b/mvp/b2c/src/app/panel/actions.ts index e0d8351..9ca1346 100644 --- a/mvp/b2c/src/app/panel/actions.ts +++ b/mvp/b2c/src/app/panel/actions.ts @@ -3,18 +3,12 @@ import { and, eq } from 'drizzle-orm'; import { revalidatePath } from 'next/cache'; import { db } from '@/db'; -import { leads, leadEstadoHistory, leadPipelineEventos, precisionHistory, tenants } from '@/db/schema'; -import { TENANT_SLUG } from '@/lib/funnel'; +import { leads, leadEstadoHistory, leadPipelineEventos, precisionHistory } from '@/db/schema'; +import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user'; import { getPricingConfig, getCatalog } from '@/db/pricing-queries'; import { computeBudget } from '@/budget'; import type { BudgetInputs } from '@/budget/types'; -async function getTenantId(): Promise { - const [tenant] = await db.select().from(tenants).where(eq(tenants.slug, TENANT_SLUG)).limit(1); - if (!tenant) throw new Error('Tenant no encontrado.'); - return tenant.id; -} - type Estado = (typeof leads.estado.enumValues)[number]; export async function cambiarEstado(leadId: string, estado: Estado) { diff --git a/mvp/b2c/src/db/pricing-queries.ts b/mvp/b2c/src/db/pricing-queries.ts index f05aeeb..fae9b03 100644 --- a/mvp/b2c/src/db/pricing-queries.ts +++ b/mvp/b2c/src/db/pricing-queries.ts @@ -1,14 +1,8 @@ import { eq } from 'drizzle-orm'; import { db } from './index'; -import { pricingConfig, catalogItems, tenants } from './schema'; -import { TENANT_SLUG } from '@/lib/funnel'; +import { pricingConfig, catalogItems } from './schema'; import type { PricingConfig, CatalogItem, ManoObraKey } from '@/budget/types'; - -async function getTenantId(): Promise { - const [tenant] = await db.select().from(tenants).where(eq(tenants.slug, TENANT_SLUG)).limit(1); - if (!tenant) throw new Error(`Tenant "${TENANT_SLUG}" no existe. ¿Has corrido npm run db:seed?`); - return tenant.id; -} +import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user'; const MANO_OBRA_DEFAULT: Record = { demolicion: 0, diff --git a/mvp/b2c/src/db/queries.ts b/mvp/b2c/src/db/queries.ts index 457da53..d3862aa 100644 --- a/mvp/b2c/src/db/queries.ts +++ b/mvp/b2c/src/db/queries.ts @@ -6,15 +6,8 @@ import { leadEstadoHistory, leadPipelineEventos, precisionHistory, - tenants, } from './schema'; -import { TENANT_SLUG } from '@/lib/funnel'; - -async function getTenantId(): Promise { - const [tenant] = await db.select().from(tenants).where(eq(tenants.slug, TENANT_SLUG)).limit(1); - if (!tenant) throw new Error(`Tenant "${TENANT_SLUG}" no existe. ¿Has corrido npm run db:seed?`); - return tenant.id; -} +import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user'; export type LeadFiltro = (typeof leads.estado.enumValues)[number] | 'todos';