fix hof ocm
This commit is contained in:
parent
cd1d3db553
commit
f2050f287c
@ -6,93 +6,19 @@ import * as ghost_ocm_area from "./ghost_ocm_area";
|
|||||||
import * as ghost_area from "./ghost_area";
|
import * as ghost_area from "./ghost_area";
|
||||||
|
|
||||||
|
|
||||||
// Save ghost battle result
|
// Get OCM Ghost Trail
|
||||||
export async function getOCMGhostTrail(carId: number, trailId: number)
|
export async function getOCMGhostTrail(carId: number, trailId: number)
|
||||||
{
|
{
|
||||||
// Get current date
|
// Get current date
|
||||||
let date = Math.floor(new Date().getTime() / 1000);
|
let date = Math.floor(new Date().getTime() / 1000);
|
||||||
|
|
||||||
// Get current / previous active OCM Event
|
let ghost_trails = await prisma.oCMTop1GhostTrail.findFirst({
|
||||||
let ocmEventDate = await prisma.oCMEvent.findFirst({
|
|
||||||
where: {
|
where: {
|
||||||
// qualifyingPeriodStartAt is less than current date
|
carId: carId,
|
||||||
qualifyingPeriodStartAt: { lte: date },
|
dbId: trailId,
|
||||||
|
|
||||||
// competitionEndAt is greater than current date
|
|
||||||
competitionEndAt: { gte: date },
|
|
||||||
},
|
|
||||||
orderBy:
|
|
||||||
{
|
|
||||||
competitionEndAt: 'desc',
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!(ocmEventDate))
|
|
||||||
{
|
|
||||||
ocmEventDate = await prisma.oCMEvent.findFirst({
|
|
||||||
orderBy:
|
|
||||||
{
|
|
||||||
competitionEndAt: 'desc',
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let ghost_trails: OCMTop1GhostTrail | null;
|
|
||||||
// Current date is OCM main draw
|
|
||||||
if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date)
|
|
||||||
{
|
|
||||||
// Get Current OCM Period
|
|
||||||
let OCMCurrentPeriod = await prisma.oCMPeriod.findFirst({
|
|
||||||
where: {
|
|
||||||
competitionDbId: ocmEventDate!.dbId,
|
|
||||||
startAt:
|
|
||||||
{
|
|
||||||
lte: date, // competitionStartAt is less than current date
|
|
||||||
},
|
|
||||||
closeAt:
|
|
||||||
{
|
|
||||||
gte: date, // competitionCloseAt is greater than current date
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ghost_trails = await prisma.oCMTop1GhostTrail.findFirst({
|
|
||||||
where: {
|
|
||||||
carId: carId,
|
|
||||||
dbId: trailId,
|
|
||||||
competitionId: ocmEventDate!.competitionId,
|
|
||||||
periodId: OCMCurrentPeriod!.periodId
|
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
playedAt: 'desc'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Current date is OCM qualifying day
|
|
||||||
else if(ocmEventDate!.qualifyingPeriodStartAt < date && ocmEventDate!.qualifyingPeriodCloseAt > date)
|
|
||||||
{
|
|
||||||
ghost_trails = await prisma.oCMTop1GhostTrail.findFirst({
|
|
||||||
where: {
|
|
||||||
carId: carId,
|
|
||||||
dbId: trailId,
|
|
||||||
competitionId: ocmEventDate!.competitionId,
|
|
||||||
periodId: 0
|
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
playedAt: 'desc'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ghost_trails = await prisma.oCMTop1GhostTrail.findFirst({
|
|
||||||
where: {
|
|
||||||
carId: carId,
|
|
||||||
dbId: trailId,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let areaVal = 0;
|
let areaVal = 0;
|
||||||
let rampVal = 0;
|
let rampVal = 0;
|
||||||
let pathVal = 0;
|
let pathVal = 0;
|
||||||
@ -124,6 +50,21 @@ export async function getOCMGhostTrail(carId: number, trailId: number)
|
|||||||
{
|
{
|
||||||
console.log('OCM Ghost Trail not found');
|
console.log('OCM Ghost Trail not found');
|
||||||
|
|
||||||
|
// Get current / previous active OCM Event
|
||||||
|
let ocmEventDate = await prisma.oCMEvent.findFirst({
|
||||||
|
where: {
|
||||||
|
// qualifyingPeriodStartAt is less than current date
|
||||||
|
qualifyingPeriodStartAt: { lte: date },
|
||||||
|
|
||||||
|
// competitionEndAt is greater than current date
|
||||||
|
competitionEndAt: { gte: date },
|
||||||
|
},
|
||||||
|
orderBy:
|
||||||
|
{
|
||||||
|
competitionEndAt: 'desc',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Calling OCM Area function (BASE_PATH/src/util/games/ghost_ocm.ts)
|
// Calling OCM Area function (BASE_PATH/src/util/games/ghost_ocm.ts)
|
||||||
let OCMArea = await ghost_ocm_area.OCMArea(ocmEventDate!.competitionId);
|
let OCMArea = await ghost_ocm_area.OCMArea(ocmEventDate!.competitionId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user