Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 300dceeb4b | |||
| ad01976fb9 | |||
| 6880eb92f5 |
@@ -586,7 +586,40 @@ export class MatchesService {
|
|||||||
date: new Date(Number(liveMatch.mstUtc)),
|
date: new Date(Number(liveMatch.mstUtc)),
|
||||||
// Fill missing relations with empty arrays
|
// Fill missing relations with empty arrays
|
||||||
teamStats: [],
|
teamStats: [],
|
||||||
playerParticipations: [],
|
playerParticipations: (() => {
|
||||||
|
const parsed: Array<{ teamId: string; isStarting: boolean; shirtNumber: string | number | null; position: string | null; player: { id: string; name: string } }> = [];
|
||||||
|
if (liveMatch.lineups && typeof liveMatch.lineups === 'object') {
|
||||||
|
const lu = liveMatch.lineups as Record<string, any>;
|
||||||
|
const addPlayers = (teamLu: any, teamId: string | null) => {
|
||||||
|
if (!teamLu || !teamId) return;
|
||||||
|
if (teamLu.xi && Array.isArray(teamLu.xi)) {
|
||||||
|
teamLu.xi.forEach((p: any) => {
|
||||||
|
parsed.push({
|
||||||
|
teamId,
|
||||||
|
isStarting: true,
|
||||||
|
shirtNumber: p.shirtNumber || p.number,
|
||||||
|
position: p.position || p.pos,
|
||||||
|
player: { id: p.personId || p.id || p.playerId || 'unknown', name: p.matchName || p.name || p.playerName || 'Bilinmiyor' }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (teamLu.subs && Array.isArray(teamLu.subs)) {
|
||||||
|
teamLu.subs.forEach((p: any) => {
|
||||||
|
parsed.push({
|
||||||
|
teamId,
|
||||||
|
isStarting: false,
|
||||||
|
shirtNumber: p.shirtNumber || p.number,
|
||||||
|
position: p.position || p.pos,
|
||||||
|
player: { id: p.personId || p.id || p.playerId || 'unknown', name: p.matchName || p.name || p.playerName || 'Bilinmiyor' }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
addPlayers(lu.home, liveMatch.homeTeamId);
|
||||||
|
addPlayers(lu.away, liveMatch.awayTeamId);
|
||||||
|
}
|
||||||
|
return parsed;
|
||||||
|
})(),
|
||||||
playerEvents: [],
|
playerEvents: [],
|
||||||
oddCategories: [], // Will handle odds parsing below
|
oddCategories: [], // Will handle odds parsing below
|
||||||
officials: [],
|
officials: [],
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable, Logger } from "@nestjs/common";
|
import { Injectable, Logger } from "@nestjs/common";
|
||||||
import { Cron } from "@nestjs/schedule";
|
import { Cron } from "@nestjs/schedule";
|
||||||
import { HttpService } from "@nestjs/axios";
|
import { HttpService } from "@nestjs/axios";
|
||||||
import { PrismaService } from "../database/prisma.service";
|
import { PrismaService } from "../database/prisma.service";
|
||||||
@@ -182,7 +182,9 @@ export class DataFetcherTask {
|
|||||||
this.logger.log("syncLiveMatches START");
|
this.logger.log("syncLiveMatches START");
|
||||||
|
|
||||||
const today = getDateStringInTimeZone(new Date(), this.timeZone);
|
const today = getDateStringInTimeZone(new Date(), this.timeZone);
|
||||||
|
const tomorrow = getShiftedDateStringInTimeZone(1, this.timeZone);
|
||||||
await this.syncMatchList(today);
|
await this.syncMatchList(today);
|
||||||
|
await this.syncMatchList(tomorrow);
|
||||||
await this.updateLiveScores();
|
await this.updateLiveScores();
|
||||||
await this.fetchOddsForMatches();
|
await this.fetchOddsForMatches();
|
||||||
await this.fillMissingLineups();
|
await this.fillMissingLineups();
|
||||||
@@ -432,7 +434,10 @@ export class DataFetcherTask {
|
|||||||
|
|
||||||
for (const match of toUpdate) {
|
for (const match of toUpdate) {
|
||||||
try {
|
try {
|
||||||
const formation = await this.scraper.fetchStartingFormation(match.id);
|
const [formation, substitutions] = await Promise.all([
|
||||||
|
this.scraper.fetchStartingFormation(match.id),
|
||||||
|
this.scraper.fetchSubstitutions(match.id),
|
||||||
|
]);
|
||||||
const sidelined = match.matchSlug
|
const sidelined = match.matchSlug
|
||||||
? await this.scraper.fetchSidelinedPlayers(
|
? await this.scraper.fetchSidelinedPlayers(
|
||||||
match.id,
|
match.id,
|
||||||
@@ -440,11 +445,26 @@ export class DataFetcherTask {
|
|||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
// Normalize to same home.xi/away.xi format used by processMatchOdds
|
||||||
|
let normalizedLineups: Record<string, unknown> | null = null;
|
||||||
|
if (formation || substitutions) {
|
||||||
|
normalizedLineups = {
|
||||||
|
home: {
|
||||||
|
xi: formation?.stats?.home || [],
|
||||||
|
subs: substitutions?.stats?.home || [],
|
||||||
|
},
|
||||||
|
away: {
|
||||||
|
xi: formation?.stats?.away || [],
|
||||||
|
subs: substitutions?.stats?.away || [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
await this.prisma.liveMatch.update({
|
await this.prisma.liveMatch.update({
|
||||||
where: { id: match.id },
|
where: { id: match.id },
|
||||||
data: {
|
data: {
|
||||||
lineups: formation
|
lineups: normalizedLineups
|
||||||
? JSON.parse(JSON.stringify(formation))
|
? JSON.parse(JSON.stringify(normalizedLineups))
|
||||||
: Prisma.JsonNull,
|
: Prisma.JsonNull,
|
||||||
sidelined: sidelined
|
sidelined: sidelined
|
||||||
? JSON.parse(JSON.stringify(sidelined))
|
? JSON.parse(JSON.stringify(sidelined))
|
||||||
@@ -810,8 +830,8 @@ export class DataFetcherTask {
|
|||||||
const matchTime = Number(match.mstUtc);
|
const matchTime = Number(match.mstUtc);
|
||||||
const diffHours = (matchTime - now) / (1000 * 60 * 60);
|
const diffHours = (matchTime - now) / (1000 * 60 * 60);
|
||||||
|
|
||||||
// Fetch if between -3 hours (started) and +4 hours (upcoming)
|
// Fetch if between -3 hours (started) and +24 hours (upcoming)
|
||||||
if (diffHours < 4 && diffHours > -3) {
|
if (diffHours < 24 && diffHours > -3) {
|
||||||
// Lineups
|
// Lineups
|
||||||
try {
|
try {
|
||||||
const [startingFormation, substitutions] = await Promise.all([
|
const [startingFormation, substitutions] = await Promise.all([
|
||||||
@@ -1269,3 +1289,4 @@ export class DataFetcherTask {
|
|||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user