Closed krissolui closed 8 months ago
Proposed Data Schema:
interface League {
id: number;
season: number;
name?: string;
country?: string;
logo?: string;
flag?: string;
}
interface Fixture {
id: number;
timezone?: string;
date?: string;
timestamp?: number;
status?: {
long: string;
elapsed: number;
seconds: string;
};
}
interface TeamsData {
home: {
id: number;
goals: number;
};
away: {
id: number;
goals: number;
};
}
interface FixtureStatus {
stopped: boolean;
blocked: boolean;
finished: boolean;
}
interface OddsValue {
value: string;
odd: string;
handicap?: string | null;
main?: boolean | null;
suspended?: boolean;
}
interface Odds {
id: number;
name: string;
values: OddsValue[];
}
interface BookMaker {
id: number;
name: string;
bets: Odds[];
}
interface PreMatchOddsResponse {
league: League;
fixture: Fixture;
update: string;
bookmakers: BookMaker[];
}
interface InPlayOddsResponse {
fixture: Fixture;
league: League;
teams: TeamsData;
status: FixtureStatus;
update: string;
odds: Odds[];
}
const preMatchOdds: PreMatchOddsResponse[] = [
{
league: {
id: 116,
name: 'Vysshaya Liga',
country: 'Belarus',
logo: 'https://media.api-sports.io/football/leagues/116.png',
flag: 'https://media.api-sports.io/flags/by.svg',
season: 2020,
},
fixture: {
id: 326090,
timezone: 'UTC',
date: '2020-05-15T15:00:00+00:00',
timestamp: 1589554800,
},
update: '2020-05-15T09:49:32+00:00',
bookmakers: [
{
id: 6,
name: 'Bwin',
bets: [
{
id: 1,
name: 'Match Winner',
values: [
{
value: 'Away',
odd: '2.95',
},
{
value: 'Draw',
odd: '2.95',
},
{
value: 'Home',
odd: '2.50',
},
],
},
],
},
],
},
];
const inPlayOdds: InPlayOddsResponse[] = [
{
fixture: {
id: 721238,
status: {
long: 'Second Half',
elapsed: 62,
seconds: '62:14',
},
},
league: {
id: 30,
season: 2022,
},
teams: {
home: {
id: 1563,
goals: 1,
},
away: {
id: 1565,
goals: 0,
},
},
status: {
stopped: false,
blocked: false,
finished: false,
},
update: '2022-01-27T16:21:01+00:00',
odds: [
{
id: 59,
name: 'Fulltime Result',
values: [
{
value: 'Home',
odd: '1.3',
handicap: null,
main: null,
suspended: false,
},
{
value: 'Draw',
odd: '4.333',
handicap: null,
main: null,
suspended: false,
},
{
value: 'Away',
odd: '17',
handicap: null,
main: null,
suspended: false,
},
],
},
],
},
];
interface OddsRecordValue {
value: string;
odds: number[];
handicap?: string | null;
main?: boolean | null;
suspended?: boolean;
}
interface OddsRecord {
id: number;
name: string;
values: OddsRecordValue[];
}
interface MatchInfo {
league: League;
fixture: Fixture;
isInPlay: boolean;
update: string;
status?: FixtureStatus; // In-play match only
odds: OddsRecord[];
}
const matchesData: MatchInfo[] = [
{
league: {
id: 30,
season: 2020,
},
fixture: {
id: 1002,
},
isInPlay: false,
update: '2020-05-15T09:49:32+00:00',
status: {
stopped: false,
blocked: false,
finished: false,
},
odds: [
{
id: 1,
name: 'Match Winner',
values: [
{
value: 'Home',
odds: [1.3],
handicap: null,
main: null,
suspended: false,
},
{
value: 'Draw',
odds: [4.333],
handicap: null,
main: null,
suspended: false,
},
{
value: 'Away',
odds: [17],
handicap: null,
main: null,
suspended: false,
},
],
},
],
},
];
// Permanent
type League = {
id: number; [idx]
name: string;
country: string;
logo: string;
flag: string;
}
collection & type Team = {
id: number; [idx]
name: string;
code: string;
logo: string;
}
// Clear after game end
collection Match {
id: number; [idx]
startTime: timestamp (UTC with date);
league: League;
home: Team;
away: Team;
lastUpdated: timestamp (optional ?);
ttl: timestamp (UTC) [when to delete data];
}
collection Odd = {
matchId: number;
bookMakerId: number;
bookMakerName: string;
timestamp: timestamp (UTC)
home: number;
away: number;
draw: number;
}
@charrrleee please take a look. i am not sure the best way to do it in NoSQL.
Confirmed
Database: MongoDB Library: Mongoose
API Response Structures:
Data models: