hkjc-api
Version:
Node.js package for communicating with HKJC GraphQL API
127 lines (126 loc) • 5.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FootballAPI = void 0;
const client_1 = require("../client");
const footballMatchesQuery_1 = require("../query/footballMatchesQuery");
class FootballAPI {
constructor(client) {
this.client = client || client_1.defaultClient;
}
/**
* Get all football matches with associated odds
* @param options Optional parameters to filter matches
* @returns A list of football matches
*/
async getAllFootballMatches(options = {}) {
const { startDate = null, endDate = null, tournIds = null, matchIds = null, oddsTypes = [
"HAD", "EHA", "SGA", "CHP", "TQL", "FHA", "HHA", "HDC", "EDC", "HIL",
"EHL", "FHL", "CHL", "ECH", "FCH", "CRS", "ECS", "FCS", "FTS", "TTG",
"ETG", "OOE", "FGS", "HFT", "MSP", "NTS", "ENT", "FHH", "FHC", "CHD",
"ECD", "EHH", "AGS", "LGS"
], featuredMatchesOnly = false, frontEndIds = null, earlySettlementOnly = false, showAllMatch = false, startIndex = null, endIndex = null } = options;
try {
const response = await this.client.request(footballMatchesQuery_1.footballMatchesQuery, {
fbOddsTypes: oddsTypes,
fbOddsTypesM: oddsTypes,
startDate,
endDate,
tournIds,
matchIds,
featuredMatchesOnly,
frontEndIds,
earlySettlementOnly,
showAllMatch,
startIndex,
endIndex
});
return response && response.matches ? response.matches : [];
}
catch (error) {
console.error('Error fetching football matches:', error);
return [];
}
}
/**
* Get detailed information for a specific football match
* @param matchId The ID of the match to retrieve
* @param oddsTypes The types of odds to retrieve for the match
* @returns Detailed information for the specified match
*/
async getFootballMatchDetails(matchId, oddsTypes) {
if (!matchId) {
throw new Error('Match ID is required');
}
const defaultOddsTypes = [
"HAD", "EHA", "SGA", "CHP", "TQL", "FHA", "HHA", "HDC", "EDC", "HIL",
"EHL", "FHL", "CHL", "ECH", "FCH", "CRS", "ECS", "FCS", "FTS", "TTG",
"ETG", "OOE", "FGS", "HFT", "MSP", "NTS", "ENT", "FHH", "FHC", "CHD",
"ECD", "EHH", "AGS", "LGS"
];
try {
const response = await this.client.request(footballMatchesQuery_1.footballMatchDetailsQuery, {
matchIds: [matchId],
fbOddsTypes: oddsTypes || defaultOddsTypes,
fbOddsTypesM: oddsTypes || defaultOddsTypes,
featuredMatchesOnly: false,
startDate: null,
endDate: null,
tournIds: null,
tournId: null,
tournProfileId: null,
subType: null,
startIndex: null,
endIndex: null,
frontEndIds: null,
earlySettlementOnly: false,
showAllMatch: false
});
if (response && response.matches && response.matches.length > 0) {
return response.matches[0];
}
return null;
}
catch (error) {
console.error('Error fetching football match details:', error);
return null;
}
}
/**
* Get running match data using the specific running query
* @param matchId Single match ID (string or number)
* @returns Football match data using the running query
*/
async getRunningMatch(matchId) {
// Convert single ID to array format for the API call
const matchIds = [String(matchId)];
// Default variables based on variable.json
const fbOddsTypes = [
"HAD", "EHA", "CHP", "TQL", "FHA", "HHA", "HDC", "EDC", "HIL",
"EHL", "FHL", "CHL", "ECH", "FCH", "CRS", "ECS", "FCS", "FTS",
"TTG", "ETG", "NTS", "ENT", "FHH", "FHC", "CHD", "ECD", "EHH"
];
try {
const response = await this.client.request(footballMatchesQuery_1.runningMatchQuery, {
fbOddsTypes,
fbOddsTypesM: fbOddsTypes,
inplayOnly: true,
featuredMatchesOnly: false,
startDate: null,
endDate: null,
tournIds: null,
matchIds,
startIndex: null,
endIndex: null,
frontEndIds: null,
earlySettlementOnly: false,
showAllMatch: false
});
return response && response.matches ? response.matches : [];
}
catch (error) {
console.error('Error fetching running match data:', error);
return [];
}
}
}
exports.FootballAPI = FootballAPI;