T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.ca/public_html/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.ca/public_html/scripts/add-competition-features.ts
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function addCompetitionFeatures() {
  console.log('šŸš€ Adding competition features to the database...');

  try {
    // Add new competition fields to existing cases
    console.log('šŸ“ Updating existing cases with competition fields...');
    
    const cases = await prisma.legalCase.findMany({
      where: { isPublic: true },
      select: { id: true, title: true }
    });

    for (const case_ of cases) {
      // Randomly assign some cases as competitions for demo purposes
      const shouldBeCompetition = Math.random() < 0.3; // 30% chance
      
      if (shouldBeCompetition) {
        const competitionTypes = ['AUCTION', 'TENDER', 'NEGOTIATION'];
        const competitionType = competitionTypes[Math.floor(Math.random() * competitionTypes.length)];
        
        // Set deadline to 7-30 days from now
        const deadline = new Date();
        deadline.setDate(deadline.getDate() + Math.floor(Math.random() * 23) + 7);
        
        // Set minimum bid between $500 and $5000
        const minimumBid = Math.floor(Math.random() * 4500) + 500;
        
        // Set current highest bid (if any)
        const currentHighestBid = Math.random() < 0.5 ? minimumBid + Math.floor(Math.random() * 2000) : null;
        
        // Set total bidders
        const totalBidders = currentHighestBid ? Math.floor(Math.random() * 5) + 1 : 0;
        
        await prisma.legalCase.update({
          where: { id: case_.id },
          data: {
            competitionType,
            competitionDeadline: deadline,
            minimumBid,
            currentHighestBid,
            totalBidders,
            averageBidAmount: currentHighestBid ? currentHighestBid * 0.9 : null
          }
        });
        
        console.log(`āœ… Updated case "${case_.title}" with competition type: ${competitionType}`);
      }
    }

    // Create some sample competition participants
    console.log('šŸ‘„ Creating sample competition participants...');
    
    const lawyers = await prisma.user.findMany({
      where: { role: 'LAWYER' },
      select: { id: true, name: true }
    });

    const competitionCases = await prisma.legalCase.findMany({
      where: { 
        competitionType: { not: null },
        isPublic: true 
      },
      select: { id: true, title: true }
    });

    for (const case_ of competitionCases) {
      // Add 2-4 random lawyers as participants
      const numParticipants = Math.floor(Math.random() * 3) + 2;
      const selectedLawyers = lawyers
        .sort(() => 0.5 - Math.random())
        .slice(0, numParticipants);

      for (const lawyer of selectedLawyers) {
        try {
          await prisma.caseCompetitionParticipant.create({
            data: {
              lawyerId: lawyer.id,
              caseId: case_.id,
              status: 'ACTIVE'
            }
          });
          console.log(`āœ… Added ${lawyer.name} as participant in "${case_.title}"`);
        } catch (error) {
          // Participant might already exist
          console.log(`ā„¹ļø ${lawyer.name} already participating in "${case_.title}"`);
        }
      }
    }

    // Create some sample bids
    console.log('šŸ’° Creating sample bids...');
    
    const participants = await prisma.caseCompetitionParticipant.findMany({
      include: {
        case: {
          select: { id: true, title: true, minimumBid: true, currentHighestBid: true }
        },
        lawyer: {
          select: { id: true, name: true }
        }
      }
    });

    for (const participant of participants) {
      // 70% chance to place a bid
      if (Math.random() < 0.7) {
        const baseBid = participant.case.minimumBid || 1000;
        const bidAmount = baseBid + Math.floor(Math.random() * 2000);
        
        const bidMessages = [
          `I have extensive experience in this area of law and believe I can provide excellent representation.`,
          `My track record shows a high success rate in similar cases. I'm confident in achieving a positive outcome.`,
          `I offer competitive rates and personalized attention to every case. Let's discuss how I can help.`,
          `With my expertise and dedication, I'm committed to fighting for your rights and achieving justice.`,
          `I bring years of experience and a proven track record. I'm ready to take on this challenge.`
        ];

        const message = bidMessages[Math.floor(Math.random() * bidMessages.length)];

        try {
          await prisma.caseBid.create({
            data: {
              caseId: participant.case.id,
              lawyerId: participant.lawyer.id,
              bidAmount,
              message,
              status: 'ACTIVE'
            }
          });
          
          console.log(`āœ… ${participant.lawyer.name} placed bid of $${bidAmount} on "${participant.case.title}"`);
        } catch (error) {
          console.log(`ā„¹ļø Bid already exists for ${participant.lawyer.name} on "${participant.case.title}"`);
        }
      }
    }

    // Update case statistics
    console.log('šŸ“Š Updating case statistics...');
    
    const casesWithBids = await prisma.legalCase.findMany({
      where: { competitionType: { not: null } },
      include: {
        bids: {
          select: { bidAmount: true }
        },
        competitionParticipants: {
          select: { id: true }
        }
      }
    });

    for (const case_ of casesWithBids) {
      if (case_.bids.length > 0) {
        const highestBid = Math.max(...case_.bids.map(b => b.bidAmount));
        const averageBid = case_.bids.reduce((sum, b) => sum + b.bidAmount, 0) / case_.bids.length;
        
        await prisma.legalCase.update({
          where: { id: case_.id },
          data: {
            currentHighestBid: highestBid,
            averageBidAmount: averageBid,
            totalBidders: case_.competitionParticipants.length
          }
        });
        
        console.log(`āœ… Updated statistics for "${case_.title}": Highest bid $${highestBid}, Average $${averageBid.toFixed(2)}`);
      }
    }

    console.log('\nšŸŽ‰ Competition features successfully added!');
    console.log('āœ… Competition fields added to cases');
    console.log('āœ… Sample participants created');
    console.log('āœ… Sample bids placed');
    console.log('āœ… Case statistics updated');

  } catch (error) {
    console.error('āŒ Error adding competition features:', error);
    throw error;
  } finally {
    await prisma.$disconnect();
  }
}

// Run the migration
addCompetitionFeatures()
  .then(() => {
    console.log('āœ… Migration completed successfully');
    process.exit(0);
  })
  .catch((error) => {
    console.error('āŒ Migration failed:', error);
    process.exit(1);
  }); 

CasperSecurity Mini