feat: add classification-based filtering and fix company name display

- Added classification column to companies table
- Created excluded_classifications setting (default: Tools Only)
- Updated kiosk stats and activity APIs to filter by classification
- Added comprehensive classification filtering UI with checkboxes
- Support for common classifications (Tools Only, Wulff Consulting Client, Customer)
- Allow custom classification entry
- Fixed company name display in settings (convert string IDs properly)
- Classification filtering works alongside company ID exclusions
This commit is contained in:
root 2026-02-03 09:17:07 -05:00
parent 62ec703f81
commit 1d99a8f659
4 changed files with 176 additions and 10 deletions

View file

@ -14,15 +14,40 @@ async function getExcludedCompanyIds(): Promise<number[]> {
}
}
async function getExcludedClassifications(): Promise<string[]> {
try {
const result = await postgresClient.query(
`SELECT setting_value FROM kiosk_settings WHERE setting_key = 'excluded_classifications'`
);
const value = result.rows[0]?.setting_value || '';
return value ? value.split(',').map((c: string) => c.trim()).filter(Boolean) : [];
} catch (error) {
console.error('Error fetching excluded classifications:', error);
return [];
}
}
export async function GET(request: NextRequest) {
try {
// Get excluded company IDs (co-managed clients)
const excludedCompanyIds = await getExcludedCompanyIds();
const excludeCompanyFilter = excludedCompanyIds.length > 0
? `AND company_id NOT IN (${excludedCompanyIds.join(',')})`
: '';
const excludedClassifications = await getExcludedClassifications();
// Build company exclusion filter
let excludeCompanyFilter = '';
if (excludedCompanyIds.length > 0 || excludedClassifications.length > 0) {
const conditions = [];
if (excludedCompanyIds.length > 0) {
conditions.push(`company_id NOT IN (${excludedCompanyIds.join(',')})`);
}
if (excludedClassifications.length > 0) {
const classificationList = excludedClassifications.map(c => `'${c.replace(/'/g, "''")}'`).join(',');
conditions.push(`company_id NOT IN (SELECT id FROM companies WHERE classification IN (${classificationList}))`);
}
excludeCompanyFilter = `AND (${conditions.join(' AND ')})`;
}
// Critical tickets (Priority 1-3) - exclude RMM alerts (source = 8) and co-managed clients
// Critical tickets (Priority 1-3) - exclude RMM alerts (source = 8), co-managed clients, and excluded classifications
const criticalTicketsResult = await postgresClient.query(
`SELECT COUNT(*) as count
FROM tickets