CognxSafeTrack
feat(admin): add Direct Setup button for super admins on orgs without phone number
a3df350 | import 'dotenv/config'; | |
| import { PrismaClient } from '@prisma/client'; | |
| const prisma = new PrismaClient(); | |
| const TEST4_ORG_ID = '12247ec1-7629-4650-b695-237654793e0c'; | |
| const TESTCRM_ORG_ID = 'ba012b65-2289-4ded-956d-aeaaf908fb30'; | |
| const PHONE_NUMBER_ID = '1135406776315489'; | |
| const DISPLAY_PHONE = '+221788227676'; | |
| const WABA_ID = '1503271284790621'; | |
| async function main() { | |
| // 1. Read testcrm's encrypted token (copy it as-is — same ENCRYPTION_SECRET) | |
| const testcrm = await prisma.organization.findUnique({ | |
| where: { id: TESTCRM_ORG_ID }, | |
| select: { systemUserToken: true, wabaId: true } | |
| }); | |
| if (!testcrm?.systemUserToken) { | |
| throw new Error('testcrm has no systemUserToken — cannot proceed'); | |
| } | |
| console.log(`📋 Source : testcrm | waba: ${testcrm.wabaId} | token: ${testcrm.systemUserToken ? '✅' : '❌'}`); | |
| // 2. Free WABA ID from testcrm first (unique constraint) | |
| await prisma.organization.update({ | |
| where: { id: TESTCRM_ORG_ID }, | |
| data: { wabaId: null } | |
| }); | |
| console.log(`✅ WABA ID retiré de testcrm`); | |
| // 3. Copy WABA ID + encrypted token to test4 | |
| await prisma.organization.update({ | |
| where: { id: TEST4_ORG_ID }, | |
| data: { | |
| wabaId: WABA_ID, | |
| systemUserToken: testcrm.systemUserToken, | |
| systemUserTokenIssuedAt: new Date() | |
| } | |
| }); | |
| console.log(`✅ WABA ID + token copiés vers test4 (WABA: ${WABA_ID})`); | |
| // 4. Move the phone number from testcrm to test4 | |
| await prisma.whatsAppPhoneNumber.update({ | |
| where: { id: PHONE_NUMBER_ID }, | |
| data: { organizationId: TEST4_ORG_ID } | |
| }); | |
| console.log(`✅ Numéro transféré vers test4 : ${DISPLAY_PHONE}`); | |
| console.log('\n🎉 test4 est maintenant opérationnel avec le numéro', DISPLAY_PHONE); | |
| await prisma.$disconnect(); | |
| } | |
| main().catch(console.error); | |