diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index 358e9a9..4d85c54 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -639,23 +639,18 @@ export default class TerminalModule extends Module { car: true }, distinct: ["carId"], + take: 50 }) numOfParticipants = ocmParticipant.length; periodId = 0; let ranking = 0; - let maxNumber = 150; - - if(numOfParticipants < 151) - { - maxNumber = numOfParticipants; - } if(numOfParticipants > 0) { periodId = ocmParticipant[0].periodId; - for(let i=0; i 0) { - if(ocmParticipant[i].carId === body.carId) - { - let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({ - where:{ - carId: body.carId, - competitionId: ocmEventDate!.competitionId, - }, - select:{ - playedAt: true - } - }); + let userCar = await prisma.car.findFirst({ + where:{ + carId: body.carId + } + }); - // User car setting - ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({ - rank: i + 1, - result: ocmParticipant[i].result, - carId: ocmParticipant[i].carId, - name: ocmParticipant[i].car.name, - regionId: ocmParticipant[i].car.regionId, - model: ocmParticipant[i].car.model, - visualModel: ocmParticipant[i].car.visualModel, - defaultColor: ocmParticipant[i].car.defaultColor, - title: ocmParticipant[i].car.title, - level: ocmParticipant[i].car.level, - windowStickerString: ocmParticipant[i].car.windowStickerString, - playedShopName: playedShopName, - playedAt: ocmGhostrecord!.playedAt - }); + let userPlayedAt = await prisma.ghostBattleRecord.findFirst({ + where:{ + carId: body.carId + }, + select:{ + playedAt: true + } + }); - break; - } + let myRank = Number(ocmPersonalRank[0].position); + let myResult = Number(ocmPersonalRank[0].result); + + ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({ + rank: myRank, + result: myResult, + carId: userCar!.carId, + name: userCar!.name, + regionId: userCar!.regionId, + model: userCar!.model, + visualModel: userCar!.visualModel, + defaultColor: userCar!.defaultColor, + title: userCar!.title, + level: userCar!.level, + windowStickerString: userCar!.windowStickerString, + playedShopName: playedShopName, + playedAt: userPlayedAt?.playedAt || 0 + }); } } } @@ -808,37 +812,39 @@ export default class TerminalModule extends Module { { console.log('Current / Previous OCM Day : OCM has Ended'); + // Get Current OCM Period and All User's Record let ocmParticipant = await prisma.oCMTally.findMany({ where:{ competitionId: ocmEventDate!.competitionId, - periodId: 999999999 - }, - orderBy: { - result: 'desc' }, + orderBy: [ + { + result: 'desc' + }, + { + periodId: 'desc' + } + ], include:{ car: true }, - distinct: ["carId"] + distinct: ["carId"], + take: 10 }) numOfParticipants = ocmParticipant.length; periodId = 0; let ranking = 0; - let maxNumber = 150; - - if(numOfParticipants < 151) - { - maxNumber = numOfParticipants; - } if(numOfParticipants > 0) - { - for(let i=0; i 0) { - if(ocmParticipant[i].carId === body.carId) - { - let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({ - where:{ - carId: body.carId, - competitionId: ocmEventDate!.competitionId, - }, - select:{ - playedAt: true - } - }); + let userCar = await prisma.car.findFirst({ + where:{ + carId: body.carId + } + }); - // User car setting - ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({ - rank: i + 1, - result: ocmParticipant[i].result, - carId: ocmParticipant[i].carId, - name: ocmParticipant[i].car.name, - regionId: ocmParticipant[i].car.regionId, - model: ocmParticipant[i].car.model, - visualModel: ocmParticipant[i].car.visualModel, - defaultColor: ocmParticipant[i].car.defaultColor, - title: ocmParticipant[i].car.title, - level: ocmParticipant[i].car.level, - windowStickerString: ocmParticipant[i].car.windowStickerString, - playedShopName: playedShopName, - playedAt: ocmGhostrecord!.playedAt - }); + let userPlayedAt = await prisma.ghostBattleRecord.findFirst({ + where:{ + carId: body.carId + }, + select:{ + playedAt: true + } + }); - break; - } + let myRank = Number(ocmPersonalRank[0].position); + let myResult = Number(ocmPersonalRank[0].result); + + ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({ + rank: myRank, + result: myResult, + carId: userCar!.carId, + name: userCar!.name, + regionId: userCar!.regionId, + model: userCar!.model, + visualModel: userCar!.visualModel, + defaultColor: userCar!.defaultColor, + title: userCar!.title, + level: userCar!.level, + windowStickerString: userCar!.windowStickerString, + playedShopName: playedShopName, + playedAt: userPlayedAt?.playedAt || 0 + }); } } }