fix: dashboard quotes from SalesBldr API, RMM total from datto_rmm_sites
- Replace non-existent 'quotes' DB table lookup with live SalesBldr API call - Fix RMM total: was checking 'rmm_sites' (wrong), now uses 'datto_rmm_sites' - Add SALESBLDR_API_URL/KEY to .env.local (were only in .env, not loaded by container)
This commit is contained in:
parent
414ad78c36
commit
115819bea0
1 changed files with 12 additions and 18 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { postgresClient } from '@/lib/services/postgres-client';
|
||||
import { SalesBldrClient } from '@/lib/services/salesbldr-client';
|
||||
|
||||
async function tableExists(tableName: string): Promise<boolean> {
|
||||
try {
|
||||
|
|
@ -55,12 +56,12 @@ export async function GET(request: NextRequest) {
|
|||
// Table may not exist
|
||||
}
|
||||
|
||||
// Get total RMM sites count (check if table exists first)
|
||||
// Get total RMM sites count from datto_rmm_sites
|
||||
let rmmTotal = rmmMapped;
|
||||
if (await tableExists('rmm_sites')) {
|
||||
if (await tableExists('datto_rmm_sites')) {
|
||||
try {
|
||||
const rmmTotalResult = await postgresClient.query(
|
||||
'SELECT COUNT(*) as total FROM rmm_sites'
|
||||
'SELECT COUNT(*) as total FROM datto_rmm_sites'
|
||||
);
|
||||
rmmTotal = parseInt(rmmTotalResult.rows[0]?.total || '0');
|
||||
} catch {
|
||||
|
|
@ -68,23 +69,16 @@ export async function GET(request: NextRequest) {
|
|||
}
|
||||
}
|
||||
|
||||
// Get quotes count (if quotes table exists)
|
||||
// Get quotes count from SalesBldr API
|
||||
let quotesOpen = 0;
|
||||
let quotesTotal = 0;
|
||||
if (await tableExists('quotes')) {
|
||||
try {
|
||||
const quotesResult = await postgresClient.query(
|
||||
"SELECT COUNT(*) as open FROM quotes WHERE status = 'open'"
|
||||
);
|
||||
quotesOpen = parseInt(quotesResult.rows[0]?.open || '0');
|
||||
|
||||
const quotesTotalResult = await postgresClient.query(
|
||||
'SELECT COUNT(*) as total FROM quotes'
|
||||
);
|
||||
quotesTotal = parseInt(quotesTotalResult.rows[0]?.total || '0');
|
||||
} catch {
|
||||
// Ignore error
|
||||
}
|
||||
try {
|
||||
const salesbldr = new SalesBldrClient();
|
||||
const openQuotes = await salesbldr.getOpenQuotes(1000);
|
||||
quotesOpen = openQuotes.total ?? openQuotes.results?.length ?? 0;
|
||||
quotesTotal = quotesOpen;
|
||||
} catch {
|
||||
// SalesBldr not configured or unavailable
|
||||
}
|
||||
|
||||
const stats = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue