File size: 2,291 Bytes
082d3db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function fixAnomalies() {
    console.log("🛠️ Démarrage de la correction des anomalies QA...");

    // 1. Fix Pitch Deck Badges on Day 12
    const day12s = await prisma.trackDay.findMany({
        where: { dayNumber: 12 }
    });

    let day12Fixed = 0;
    for (const day of day12s) {
        let badges: string[] = [];
        if (day.badges) {
            try {
                badges = typeof day.badges === 'string' ? JSON.parse(day.badges as string) : day.badges as string[];
            } catch (e) {
                // Ignore parse errors if somehow invalid
            }
        }

        if (!badges.includes("PITCH_DECK") && !badges.includes("PITCH_AI") && !badges.includes("DOCUMENT_GENERATION")) {
            badges.push("PITCH_AI");

            await prisma.trackDay.update({
                where: { id: day.id },
                data: { badges }
            });
            console.log(`✅ Fixed badges for ${day.trackId} Day 12: added PITCH_AI`);
            day12Fixed++;
        }
    }

    // 2. Fix empty activityLabel in BusinessProfiles to avoid Pitch Card crashes
    const profiles = await prisma.businessProfile.findMany({
        where: {
            OR: [
                { activityLabel: null },
                { activityLabel: "" }
            ]
        },
        include: { user: true }
    });

    let profileFixed = 0;
    for (const profile of profiles) {
        let label = profile.activityLabel;
        if (!label || label.trim() === "") {
            label = profile.user?.activity || "Projet Entrepreneurial";
            await prisma.businessProfile.update({
                where: { id: profile.id },
                data: { activityLabel: label }
            });
            console.log(`✅ Fixed activityLabel for user ${profile.userId} -> ${label}`);
            profileFixed++;
        }
    }

    console.log(`\n🎉 Bilan des corrections :`);
    console.log(`- ${day12Fixed} Jours 12 mis à jour avec la métadonnée PITCH_AI`);
    console.log(`- ${profileFixed} Profils complétés avec une activityLabel par défaut`);

    await prisma.$disconnect();
}

fixAnomalies().catch(e => {
    console.error(e);
    process.exit(1);
});