Skip to content

Commit

Permalink
playerprop data fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
avalos010 committed Oct 7, 2024
1 parent afcf2fc commit e6b36c6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 25 deletions.
12 changes: 7 additions & 5 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,17 @@ export async function getPointOdds(sport = "upcoming") {

export async function getPlayerProps(
sport: string,
eventid: string,
markets = "batter_hits"
eventid: string
// markets = "batter_hits"
) {
try {
const odds = await fetch(
`${baseURL}/v4/sports/${sport}/events/${eventid}/odds/?apiKey=${apiKey}&markets=${markets}`
`${baseURL}/v4/sports/${sport}/events/${eventid}/odds/?apiKey=${apiKey}&regions=us&oddsFormat=american`
);
if (odds) {
return odds;

const data = odds.json();
if (data) {
return data ?? [];
}
return [];
} catch (error) {
Expand Down
15 changes: 0 additions & 15 deletions src/app/odds/[sport]/playerprops/[eventid]/page.tsx

This file was deleted.

2 changes: 2 additions & 0 deletions src/app/odds/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import MoneyLine from "@/components/Moneyline";
async function Odds() {
const odds = await getMoneyLineOdds();

//https://api.the-odds-api.com/v4/sports/americanfootball_nfl/events/a512a48a58c4329048174217b2cc7ce0/odds?apiKey=YOUR_API_KEY&regions=us&markets=player_pass_tds&oddsFormat=american(opens new window)

if (!odds) {
notFound();
}
Expand Down
23 changes: 23 additions & 0 deletions src/app/odds/playerProps/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { URLSearchParams } from "url";
import { getPlayerProps } from "../../../../lib/api";

interface PlayerPropsParams {
searchParams: {
sport: string;
event: string;
};
}
const playerProps = async ({ searchParams }: PlayerPropsParams) => {
const { sport, event: eventId } = searchParams;

const props = await getPlayerProps(sport, eventId);

console.log(props);
return (
<div>
<h1>Player Props real</h1>
</div>
);
};

export default playerProps;
16 changes: 13 additions & 3 deletions src/components/OddsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import { ReactNode } from "react";
import { Odds } from "../../lib/api";
import Link from "next/link";

function OddsTable({ oddsItem, home, away, points, draw }: OddsTableProps) {
const { away_team, bookmakers, home_team } = oddsItem;
Expand All @@ -12,9 +13,18 @@ function OddsTable({ oddsItem, home, away, points, draw }: OddsTableProps) {
if (!points) {
return (
<div className="m-5 flex flex-col shadow-lg">
<h2 className="text-3xl">
{home_team} vs {away_team}
</h2>
<div className="flex flex-row flex-wrap justify-between p-2">
<h2 className="text-3xl">
{home_team} vs {away_team}
</h2>
<Link
href={`/odds/playerProps/?sport=${oddsItem.sport_key}&event=${oddsItem.id}`}
className="text-lg p-2 text-cyan-600 w-max"
>
Player Props
</Link>
</div>

<p className="text-cyan-700 text-sm">{startTime}</p>
<div className="p-3">
<span>{home_team}</span>
Expand Down
10 changes: 8 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app/odds/[sport]/playerprops"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"src/app/odds/playerProps"
],
"exclude": ["node_modules"],
"baseUrl": "http://localhost:3000",
"baseUrl": "http://localhost:3000"
}

0 comments on commit e6b36c6

Please sign in to comment.