fix: use dynamic tenant_id from user session for html dashboard
This commit is contained in:
@@ -1,29 +1,29 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { htmlTemplate } from './template';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
import { resolveActiveTenant } from '@/lib/tenant-context';
|
||||
|
||||
export async function GET() {
|
||||
const supabase = await createClient();
|
||||
const tenant_id = '8bec977a-6032-4759-aa7f-b5042081f450';
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
if (!user) {
|
||||
return new NextResponse('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const { data: adDaily } = await supabase
|
||||
.from('ad_daily')
|
||||
.select('*')
|
||||
.eq('tenant_id', tenant_id)
|
||||
.order('day', { ascending: true });
|
||||
const ctx = await resolveActiveTenant(user);
|
||||
const tenant_id = ctx.tenantId;
|
||||
|
||||
const { data: orgDaily } = await supabase
|
||||
.from('organic_daily')
|
||||
.select('*')
|
||||
.eq('tenant_id', tenant_id)
|
||||
.order('day', { ascending: true });
|
||||
let queryAd = supabase.from('ad_daily').select('*').order('day', { ascending: true });
|
||||
if (tenant_id) queryAd = queryAd.eq('tenant_id', tenant_id);
|
||||
const { data: adDaily } = await queryAd;
|
||||
|
||||
const { data: creativePipeline } = await supabase
|
||||
.from('creative_pipeline')
|
||||
.select('*')
|
||||
.order('created_at', { ascending: true });
|
||||
let queryOrg = supabase.from('organic_daily').select('*').order('day', { ascending: true });
|
||||
if (tenant_id) queryOrg = queryOrg.eq('tenant_id', tenant_id);
|
||||
const { data: orgDaily } = await queryOrg;
|
||||
|
||||
let queryPipe = supabase.from('creative_pipeline').select('*').order('created_at', { ascending: true });
|
||||
if (tenant_id) queryPipe = queryPipe.eq('tenant_id', tenant_id);
|
||||
const { data: creativePipeline } = await queryPipe;
|
||||
|
||||
// Map to K format
|
||||
const startDay = new Date();
|
||||
|
||||
Reference in New Issue
Block a user