cr
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import axios from "axios";
|
||||
|
||||
/**
|
||||
* Spor Toto API response types
|
||||
@@ -45,25 +45,25 @@ export interface SporTotoApiResponse {
|
||||
@Injectable()
|
||||
export class TotoFetcherService {
|
||||
private readonly logger = new Logger(TotoFetcherService.name);
|
||||
private readonly apiUrl = 'https://sportotov2.iddaa.com/SporToto';
|
||||
private readonly apiUrl = "https://sportotov2.iddaa.com/SporToto";
|
||||
|
||||
/**
|
||||
* Fetch current bulletin from Spor Toto API
|
||||
*/
|
||||
async fetchCurrentBulletin(): Promise<SporTotoApiResponse | null> {
|
||||
try {
|
||||
this.logger.log('Fetching current Spor Toto bulletin...');
|
||||
this.logger.log("Fetching current Spor Toto bulletin...");
|
||||
const response = await axios.get<SporTotoApiResponse>(this.apiUrl, {
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'User-Agent': 'SuggestBet/1.0',
|
||||
Accept: "application/json",
|
||||
"User-Agent": "SuggestBet/1.0",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data?.isSuccess || !response.data?.data) {
|
||||
this.logger.warn(
|
||||
'Spor Toto API returned unsuccessful response',
|
||||
"Spor Toto API returned unsuccessful response",
|
||||
response.data?.message,
|
||||
);
|
||||
return null;
|
||||
@@ -80,7 +80,7 @@ export class TotoFetcherService {
|
||||
error.response?.status,
|
||||
);
|
||||
} else {
|
||||
this.logger.error('Spor Toto fetch failed', error);
|
||||
this.logger.error("Spor Toto fetch failed", error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -93,30 +93,30 @@ export class TotoFetcherService {
|
||||
homeTeam: string;
|
||||
awayTeam: string;
|
||||
} {
|
||||
const parts = eventName.split('-');
|
||||
const parts = eventName.split("-");
|
||||
if (parts.length >= 2) {
|
||||
return {
|
||||
homeTeam: parts[0].trim(),
|
||||
awayTeam: parts.slice(1).join('-').trim(),
|
||||
awayTeam: parts.slice(1).join("-").trim(),
|
||||
};
|
||||
}
|
||||
return { homeTeam: eventName, awayTeam: '' };
|
||||
return { homeTeam: eventName, awayTeam: "" };
|
||||
}
|
||||
|
||||
/**
|
||||
* Map API result/winner to TotoMatchResult enum value
|
||||
* API returns: "1" (HOME), "0" (DRAW), "2" (AWAY)
|
||||
*/
|
||||
mapResultToEnum(winner: string | null): 'HOME' | 'DRAW' | 'AWAY' | null {
|
||||
mapResultToEnum(winner: string | null): "HOME" | "DRAW" | "AWAY" | null {
|
||||
if (!winner) return null;
|
||||
switch (winner) {
|
||||
case '1':
|
||||
return 'HOME';
|
||||
case '0':
|
||||
case 'X':
|
||||
return 'DRAW';
|
||||
case '2':
|
||||
return 'AWAY';
|
||||
case "1":
|
||||
return "HOME";
|
||||
case "0":
|
||||
case "X":
|
||||
return "DRAW";
|
||||
case "2":
|
||||
return "AWAY";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user