| 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); |
|
|