| import { PrismaClient } from '@repo/database'; |
|
|
| const prisma = new PrismaClient(); |
| const XAMLE_ID = 'default-org-id'; |
|
|
| async function main() { |
| |
| const orgs = await prisma.organization.findMany({ |
| select: { id: true, name: true, wabaId: true, systemUserToken: true } |
| }); |
|
|
| console.log('\n[ORGS]'); |
| for (const o of orgs) { |
| console.log(` ${o.name.padEnd(30)} id=${o.id} wabaId=${o.wabaId ?? 'null'} token=${o.systemUserToken ? 'OUI' : 'NON'}`); |
| } |
|
|
| |
| const source = await prisma.organization.findUnique({ |
| where: { id: XAMLE_ID }, |
| select: { systemUserToken: true, openAiApiKey: true, googleAiApiKey: true } |
| }); |
|
|
| if (!source?.systemUserToken) { |
| console.error('[ERROR] Token source introuvable.'); |
| process.exit(1); |
| } |
|
|
| |
| const target = orgs.find(o => |
| o.id !== XAMLE_ID && o.name.toLowerCase().includes('admin') |
| ); |
|
|
| if (!target) { |
| console.log('\n[INFO] Aucune org avec "admin" dans le nom trouvée — liste ci-dessus pour identifier manuellement.'); |
| process.exit(0); |
| } |
|
|
| console.log(`\n[TARGET] "${target.name}" (${target.id})`); |
|
|
| |
| await prisma.organization.update({ |
| where: { id: target.id }, |
| data: { |
| systemUserToken: source.systemUserToken, |
| openAiApiKey: source.openAiApiKey, |
| googleAiApiKey: source.googleAiApiKey, |
| } |
| }); |
|
|
| console.log('[OK] systemUserToken + clés AI copiés (wabaId non touché)'); |
| } |
|
|
| main() |
| .catch(e => { console.error(e); process.exit(1); }) |
| .finally(() => prisma.$disconnect()); |
|
|