2 * Create a test customer and move test invoices/contracts to it
4require('dotenv').config();
5const pool = require('./services/db');
7const TENANT_ID = '00000000-0000-0000-0000-000000000001';
8const TEST_INVOICE_IDS = [503, 504, 505];
9const TEST_CONTRACT_ID = 29;
11async function moveToTestCustomer() {
13 console.log('Creating test customer...\n');
15 // Create test customer
16 const customerResult = await pool.query(
17 `INSERT INTO customers (name, email, phone, address, city, state, postal_code, country, tenant_id)
18 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
19 RETURNING customer_id, name, email`,
33 const testCustomerId = customerResult.rows[0].customer_id;
34 console.log(`✅ Created test customer: ${customerResult.rows[0].name} (ID: ${testCustomerId})`);
35 console.log(` Email: ${customerResult.rows[0].email}\n`);
37 // Move invoices to test customer
38 console.log('Moving test invoices...');
39 for (const invoiceId of TEST_INVOICE_IDS) {
40 const result = await pool.query(
43 WHERE invoice_id = $2 AND tenant_id = $3
44 RETURNING invoice_id, description, total`,
45 [testCustomerId, invoiceId, TENANT_ID]
48 if (result.rows.length > 0) {
49 console.log(` ✅ Invoice #${result.rows[0].invoice_id}: $${result.rows[0].total} - ${result.rows[0].description}`);
51 console.log(` ⚠️ Invoice #${invoiceId} not found`);
55 // Move contract to test customer
56 console.log('\nMoving test contract...');
57 const contractResult = await pool.query(
60 WHERE contract_id = $2 AND tenant_id = $3
61 RETURNING contract_id, title, labor_rate`,
62 [testCustomerId, TEST_CONTRACT_ID, TENANT_ID]
65 if (contractResult.rows.length > 0) {
66 console.log(` ✅ Contract #${contractResult.rows[0].contract_id}: ${contractResult.rows[0].title} - $${contractResult.rows[0].labor_rate}/month`);
68 console.log(` ⚠️ Contract #${TEST_CONTRACT_ID} not found`);
71 console.log('\n✅ Test data organized successfully!');
72 console.log(`\n📋 Test Customer ID: ${testCustomerId}`);
73 console.log(' Name: Testing Inc');
74 console.log(' Email: test@example.com');
80 console.error('❌ Error:', error.message);