diff --git a/src/modules/cars.ts b/src/modules/cars.ts index fa8bad3..5364f59 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -155,7 +155,7 @@ export default class CarModule extends Module { announceEventModePrize: true, opponentGhost: ghostCarsNo1 || null, opponentTrailId: trailIdNo1 || null, - opponentCompetitionId: ocmEventDate!.competitionId || null + opponentCompetitionId: ocmEventDate?.competitionId || null }; // Generate the load car response message diff --git a/src/modules/startup.ts b/src/modules/startup.ts index 448edd9..7beb1d4 100644 --- a/src/modules/startup.ts +++ b/src/modules/startup.ts @@ -25,6 +25,31 @@ export default class StartupModule extends Module { // Get current / previous active OCM Event let ocmEventDate = await prisma.oCMEvent.findFirst({ + where: { + OR: [ + { + // qualifyingPeriodStartAt is less than current date + qualifyingPeriodStartAt: { lte: date }, + + // qualifyingPeriodCloseAt is greater than current date + qualifyingPeriodCloseAt: { gte: date }, + }, + { + // competitionStartAt is less than current date + competitionStartAt: { lte: date }, + + // competitionCloseAt is greater than current date + competitionCloseAt: { gte: date }, + }, + { + // competitionCloseAt is less than current date + competitionCloseAt: { lte: date }, + + // competitionEndAt is greater than current date + competitionEndAt: {gte: date }, + } + ], + }, orderBy: [ { dbId: 'desc' @@ -34,6 +59,21 @@ export default class StartupModule extends Module { }, ], }); + + if(!(ocmEventDate)) + { + ocmEventDate = await prisma.oCMEvent.findFirst({ + orderBy: [ + { + dbId: 'desc' + }, + { + competitionEndAt: 'desc', + }, + ], + }); + } + // Declare GhostCompetitionSchedule let compeSch; if(ocmEventDate) diff --git a/src/util/games/ghost_trail.ts b/src/util/games/ghost_trail.ts index 7c70750..298b737 100644 --- a/src/util/games/ghost_trail.ts +++ b/src/util/games/ghost_trail.ts @@ -11,8 +11,33 @@ export async function getOCMGhostTrail(carId: number, trailId: number) // Get current date let date = Math.floor(new Date().getTime() / 1000); - // Get current active OCM Event + // Get current / previous active OCM Event let ocmEventDate = await prisma.oCMEvent.findFirst({ + where: { + OR: [ + { + // qualifyingPeriodStartAt is less than current date + qualifyingPeriodStartAt: { lte: date }, + + // qualifyingPeriodCloseAt is greater than current date + qualifyingPeriodCloseAt: { gte: date }, + }, + { + // competitionStartAt is less than current date + competitionStartAt: { lte: date }, + + // competitionCloseAt is greater than current date + competitionCloseAt: { gte: date }, + }, + { + // competitionCloseAt is less than current date + competitionCloseAt: { lte: date }, + + // competitionEndAt is greater than current date + competitionEndAt: {gte: date }, + } + ], + }, orderBy: [ { dbId: 'desc' @@ -23,6 +48,20 @@ export async function getOCMGhostTrail(carId: number, trailId: number) ], }); + if(!(ocmEventDate)) + { + ocmEventDate = await prisma.oCMEvent.findFirst({ + orderBy: [ + { + dbId: 'desc' + }, + { + competitionEndAt: 'desc', + }, + ], + }); + } + let ghost_trails: OCMTop1GhostTrail | null; // Current date is OCM main draw if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date)