File size: 1,464 Bytes
37fb9ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import 'dotenv/config';
import path from 'path';
import dotenv from 'dotenv';
dotenv.config({ path: path.join(__dirname, '../../../../.env') });
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

async function audit() {
    const orgId = 'default-org-id';
    const org = await prisma.organization.findUnique({
        where: { id: orgId },
        include: { phoneNumbers: true }
    });

    if (!org) {
        console.log(`❌ Organization ${orgId} NOT FOUND in DB.`);
        const allOrgs = await prisma.organization.findMany({ take: 5 });
        console.log('Available Orgs:', allOrgs.map(o => ({ id: o.id, name: o.name })));
    } else {
        console.log(`✅ Organization Found: ${org.name} (${org.id})`);
        console.log('System User Token present:', !!org.systemUserToken);
        if (org.systemUserToken) {
            console.log('Token starts with enc:', org.systemUserToken.startsWith('enc:'));
        }
        console.log('Phone Numbers count:', org.phoneNumbers.length);
        if (org.phoneNumbers.length > 0) {
            console.log('First Phone Number ID:', org.phoneNumbers[0].id);
        }
    }

    const messages = await prisma.message.findMany({
        take: 5,
        orderBy: { createdAt: 'desc' }
    });
    console.log('Recent Messages:', messages.map(m => ({ id: m.id, direction: m.direction, status: m.status })));

    await prisma.$disconnect();
}

audit().catch(console.error);