File size: 1,792 Bytes
ec8f103
 
 
338c360
ec8f103
338c360
 
 
 
 
ec8f103
338c360
 
 
 
ec8f103
338c360
ec8f103
338c360
ec8f103
 
 
 
338c360
ec8f103
 
 
338c360
 
 
 
 
 
 
 
 
 
 
 
 
ec8f103
338c360
ec8f103
 
 
 
 
 
338c360
 
ec8f103
 
 
 
 
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
56
import { PrismaClient } from '@repo/database';

const prisma = new PrismaClient();
const XAMLE_ID = 'default-org-id';

async function main() {
    // Lister toutes les orgs pour trouver "xamlé admin"
    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'}`);
    }

    // Source : xamlé global
    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);
    }

    // Trouver xamlé admin (nom approximatif)
    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})`);

    // Copier token + clés AI uniquement — pas de wabaId
    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());