betterbettor / bet-better-react

Frontend of BetBetter
MIT License
0 stars 0 forks source link

Data Schema (Frontend) #1

Closed krissolui closed 8 months ago

krissolui commented 9 months ago

Define data schema for the frontend UI

louvrecly commented 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,
          },
        ],
      },
    ],
  },
];
krissolui commented 8 months ago

@louvrecly Are we missing Team info? Like name, code and logo? And are we going with "Fixture" or "Match"?

louvrecly commented 8 months ago

@louvrecly Are we missing Team info? Like name, code and logo? And are we going with "Fixture" or "Match"?

Yes, you're right. The pre-match odds response doesn't have any data on the teams playing. Probably need to use the fixture id to fetch the teams' details.

The in-play odds response only has the basic info about the teams: the id and the number of goals.

    teams: {
      home: {
        id: 1563,
        goals: 1,
      },
      away: {
        id: 1565,
        goals: 0,
      },
    },

We may need to fetch more details using the team id.

louvrecly commented 8 months ago

Refer to this comment: https://github.com/betterbettor/bet-better-server/issues/1#issuecomment-1761614921