File size: 1,912 Bytes
a3df350 | 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 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);
|