Migrar resolución de tenant del panel a la sesión
This commit is contained in:
@@ -3,18 +3,12 @@
|
|||||||
import { and, eq } from 'drizzle-orm';
|
import { and, eq } from 'drizzle-orm';
|
||||||
import { revalidatePath } from 'next/cache';
|
import { revalidatePath } from 'next/cache';
|
||||||
import { db } from '@/db';
|
import { db } from '@/db';
|
||||||
import { leads, leadEstadoHistory, leadPipelineEventos, precisionHistory, tenants } from '@/db/schema';
|
import { leads, leadEstadoHistory, leadPipelineEventos, precisionHistory } from '@/db/schema';
|
||||||
import { TENANT_SLUG } from '@/lib/funnel';
|
import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user';
|
||||||
import { getPricingConfig, getCatalog } from '@/db/pricing-queries';
|
import { getPricingConfig, getCatalog } from '@/db/pricing-queries';
|
||||||
import { computeBudget } from '@/budget';
|
import { computeBudget } from '@/budget';
|
||||||
import type { BudgetInputs } from '@/budget/types';
|
import type { BudgetInputs } from '@/budget/types';
|
||||||
|
|
||||||
async function getTenantId(): Promise<string> {
|
|
||||||
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];
|
type Estado = (typeof leads.estado.enumValues)[number];
|
||||||
|
|
||||||
export async function cambiarEstado(leadId: string, estado: Estado) {
|
export async function cambiarEstado(leadId: string, estado: Estado) {
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import { db } from './index';
|
import { db } from './index';
|
||||||
import { pricingConfig, catalogItems, tenants } from './schema';
|
import { pricingConfig, catalogItems } from './schema';
|
||||||
import { TENANT_SLUG } from '@/lib/funnel';
|
|
||||||
import type { PricingConfig, CatalogItem, ManoObraKey } from '@/budget/types';
|
import type { PricingConfig, CatalogItem, ManoObraKey } from '@/budget/types';
|
||||||
|
import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user';
|
||||||
async function getTenantId(): Promise<string> {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MANO_OBRA_DEFAULT: Record<ManoObraKey, number> = {
|
const MANO_OBRA_DEFAULT: Record<ManoObraKey, number> = {
|
||||||
demolicion: 0,
|
demolicion: 0,
|
||||||
|
|||||||
@@ -6,15 +6,8 @@ import {
|
|||||||
leadEstadoHistory,
|
leadEstadoHistory,
|
||||||
leadPipelineEventos,
|
leadPipelineEventos,
|
||||||
precisionHistory,
|
precisionHistory,
|
||||||
tenants,
|
|
||||||
} from './schema';
|
} from './schema';
|
||||||
import { TENANT_SLUG } from '@/lib/funnel';
|
import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user';
|
||||||
|
|
||||||
async function getTenantId(): Promise<string> {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type LeadFiltro = (typeof leads.estado.enumValues)[number] | 'todos';
|
export type LeadFiltro = (typeof leads.estado.enumValues)[number] | 'todos';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user