feat: add contact management functionality
- Implemented ContactForm component for creating and editing contacts. - Added ProjectContactSelector component to manage project-specific contacts. - Updated ProjectForm to include ProjectContactSelector for associating contacts with projects. - Enhanced Card component with a new CardTitle subcomponent for better structure. - Updated Navigation to include a link to the contacts page. - Added translations for contact-related terms in the i18n module. - Initialized contacts database schema and created necessary tables for contact management. - Developed queries for CRUD operations on contacts, including linking and unlinking contacts to projects. - Created a test script to validate contact queries against the database.
This commit is contained in:
54
test-contacts-query.mjs
Normal file
54
test-contacts-query.mjs
Normal file
@@ -0,0 +1,54 @@
|
||||
import db from './src/lib/db.js';
|
||||
|
||||
console.log('Testing contacts query...\n');
|
||||
|
||||
try {
|
||||
// Test 1: Basic query
|
||||
console.log('Test 1: Basic contact query');
|
||||
const basic = db.prepare('SELECT contact_id, name FROM contacts WHERE is_active = 1 LIMIT 3').all();
|
||||
console.log('✓ Basic query works:', basic.length, 'contacts\n');
|
||||
|
||||
// Test 2: With LEFT JOIN
|
||||
console.log('Test 2: With project_contacts join');
|
||||
const withJoin = db.prepare(`
|
||||
SELECT c.contact_id, c.name, COUNT(pc.project_id) as count
|
||||
FROM contacts c
|
||||
LEFT JOIN project_contacts pc ON c.contact_id = pc.contact_id
|
||||
WHERE c.is_active = 1
|
||||
GROUP BY c.contact_id
|
||||
LIMIT 3
|
||||
`).all();
|
||||
console.log('✓ Join query works:', withJoin.length, 'contacts\n');
|
||||
|
||||
// Test 3: With both joins
|
||||
console.log('Test 3: With both joins (no CASE)');
|
||||
const bothJoins = db.prepare(`
|
||||
SELECT c.contact_id, c.name, COUNT(p.project_id) as count
|
||||
FROM contacts c
|
||||
LEFT JOIN project_contacts pc ON c.contact_id = pc.contact_id
|
||||
LEFT JOIN projects p ON pc.project_id = p.project_id
|
||||
WHERE c.is_active = 1
|
||||
GROUP BY c.contact_id
|
||||
LIMIT 3
|
||||
`).all();
|
||||
console.log('✓ Both joins work:', bothJoins.length, 'contacts\n');
|
||||
|
||||
// Test 4: With CASE statement
|
||||
console.log('Test 4: With CASE statement');
|
||||
const withCase = db.prepare(`
|
||||
SELECT c.contact_id, c.name,
|
||||
COUNT(DISTINCT CASE WHEN p.is_deleted = 0 THEN p.project_id ELSE NULL END) as count
|
||||
FROM contacts c
|
||||
LEFT JOIN project_contacts pc ON c.contact_id = pc.contact_id
|
||||
LEFT JOIN projects p ON pc.project_id = p.project_id
|
||||
WHERE c.is_active = 1
|
||||
GROUP BY c.contact_id
|
||||
LIMIT 3
|
||||
`).all();
|
||||
console.log('✓ CASE query works:', withCase.length, 'contacts');
|
||||
withCase.forEach(c => console.log(` ${c.name}: ${c.count} active projects`));
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Query failed:', error.message);
|
||||
console.error(error.stack);
|
||||
}
|
||||
Reference in New Issue
Block a user