diff --git a/README.md b/README.md index 447ca916c..2cf02f633 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,16 @@ npm run dev npm run dev -- --open ``` +### Dev Environment [Codespaces] + +If you're using `codespaces` enabled for the `scores-platform` development - simply launch the +`dev` branch and once the `codespace` has successfully loaded run the following commands: + +``` +npm install -g npm@8.19.1 +npm install +``` + ### Production Environment Before creating a production version of your app, install an [adapter](https://kit.svelte.dev/docs#adapters) for your target environment. Then: diff --git a/my-server.js b/my-server.js index 6a30fd23b..efb98e6e9 100644 --- a/my-server.js +++ b/my-server.js @@ -28,7 +28,7 @@ const app = express(); * [ℹ] separate from SvelteKit endpoint in attempts to * [ℹ] identify clients (IP - address) */ -app.get('/getClientIP', (req, res, next) => { +app.get('/getClientIP', (req, res) => { const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress || diff --git a/src/lib/components/fixtures_page/head-2-head/Head_2_Head_Widget.svelte b/src/lib/components/fixtures_page/head-2-head/Head_2_Head_Widget.svelte index 58e3793cd..7f6eb288c 100644 --- a/src/lib/components/fixtures_page/head-2-head/Head_2_Head_Widget.svelte +++ b/src/lib/components/fixtures_page/head-2-head/Head_2_Head_Widget.svelte @@ -110,7 +110,8 @@ loaded = true; const responses_invalid = - response == undefined + FIXTURE_H2H == undefined + || response == undefined || response.historic_fixtures[0] == undefined || response.historic_fixtures[0]?.probabilities == undefined || response_main_sportbook == undefined @@ -146,14 +147,15 @@ FIXTURE_PROB_DATA.time = HIST_FIXTURE_DATA?.time // [ℹ] calcuate (%) of 5 matches - if (FIXTURE_INFO?.data?.home_team_name == FIXTURE_H2H?.teams_data[0].team_name) { - team1Percent = ((FIXTURE_H2H?.data?.wins_draws?.team_1 / 5) * 100) - team2Percent = ((FIXTURE_H2H?.data?.wins_draws?.team_2 / 5) * 100) - } - else { + if ((FIXTURE_H2H?.teams_data.find( ({ team_name }) => team_name == FIXTURE_INFO?.data?.home_team_name).team_id + > FIXTURE_H2H?.teams_data.find( ({ team_name }) => team_name == FIXTURE_INFO?.data?.away_team_name).team_id)) { team1Percent = ((FIXTURE_H2H?.data?.wins_draws?.team_2 / 5) * 100) team2Percent = ((FIXTURE_H2H?.data?.wins_draws?.team_1 / 5) * 100) } + else { + team1Percent = ((FIXTURE_H2H?.data?.wins_draws?.team_1 / 5) * 100) + team2Percent = ((FIXTURE_H2H?.data?.wins_draws?.team_2 / 5) * 100) + } // [ℹ] regardless of STATUS, // [ℹ] VOTE_DATA is shown until it is erased from "/odds" @@ -474,20 +476,23 @@
- - - {#each FIXTURE_H2H?.teams_data as item} -

{item?.team_name}

- {/each} - - {#each FIXTURE_H2H?.data?.last_5_data as item} -

{item?.league?.data?.name}

- {/each} + + {#if FIXTURE_H2H != undefined} + + {#each FIXTURE_H2H?.teams_data as item} +

{item?.team_name}

+ {/each} + + {#each FIXTURE_H2H?.data?.last_5_data as item} +

{item?.league?.data?.name}

+ {/each} + {/if}
@@ -661,10 +666,11 @@ color-black-2 main-txt "> - {#if FIXTURE_INFO?.data?.home_team_name == FIXTURE_H2H?.teams_data[0].team_name} - {FIXTURE_H2H?.data?.wins_draws?.team_1} - {:else} + {#if (FIXTURE_H2H?.teams_data.find( ({ team_name }) => team_name == FIXTURE_INFO?.data?.home_team_name).team_id + > FIXTURE_H2H?.teams_data.find( ({ team_name }) => team_name == FIXTURE_INFO?.data?.away_team_name).team_id)} {FIXTURE_H2H?.data?.wins_draws?.team_2} + {:else} + {FIXTURE_H2H?.data?.wins_draws?.team_1} {/if}

- {#if FIXTURE_INFO?.data?.away_team_name == FIXTURE_H2H?.teams_data[0].team_name} - {FIXTURE_H2H?.data?.wins_draws?.team_1} - {:else} + {#if (FIXTURE_H2H?.teams_data.find( ({ team_name }) => team_name == FIXTURE_INFO?.data?.away_team_name).team_id + > FIXTURE_H2H?.teams_data.find( ({ team_name }) => team_name == FIXTURE_INFO?.data?.home_team_name).team_id)} {FIXTURE_H2H?.data?.wins_draws?.team_2} + {:else} + {FIXTURE_H2H?.data?.wins_draws?.team_1} {/if}

- {FIXTURE_H2H?.teams_data[0].team_name} + {FIXTURE_H2H?.teams_data.find( ({ team_name }) => team_name == FIXTURE_INFO?.data?.home_team_name).team_name}

{/if}
- {FIXTURE_H2H?.teams_data[1].team_name} + {FIXTURE_H2H?.teams_data.find( ({ team_name }) => team_name == FIXTURE_INFO?.data?.away_team_name).team_name}

{/if}
{ - // ... get all the `sportbook_details` data from `Firebase DB`; - return get(child(ref(db_real), `sportsbook_details`)).then((snapshot) => { - - // ... existance verifying; + return await get(child(ref(db_real), `sportsbook_details`)).then((snapshot) => { if (snapshot.exists()) { - - // ... return RAW DATA; return snapshot.val() - - // ... else, return `empty`; } else { - - // ... return null; return; } }) diff --git a/src/lib/firebase/fixtures_odds/index.ts b/src/lib/firebase/fixtures_odds/index.ts index e75a1ae6c..e83047f0f 100644 --- a/src/lib/firebase/fixtures_odds/index.ts +++ b/src/lib/firebase/fixtures_odds/index.ts @@ -5,7 +5,7 @@ import { child, get, ref } from 'firebase/database' export async function getLivescoresNow(): Promise < unknown > { - return get(child(ref(db_real), `livescores_now`)) + return await get(child(ref(db_real), `livescores_now`)) .then((snapshot) => { if (snapshot.exists()) { return snapshot.val() @@ -26,7 +26,7 @@ export async function getOdds ( // [ℹ] iterate over ALL fixtures // [ℹ] of SELECTED season - for (const season_fixture_date_group of fixtures_arr_filter) { + for await (const season_fixture_date_group of fixtures_arr_filter) { // [ℹ] convert the datetime to the correct variables to search for the fixture; const year_: string = new Date(season_fixture_date_group.date).getFullYear().toString(); @@ -39,7 +39,7 @@ export async function getOdds ( // [ℹ] iterater over fixtures // [ℹ] [BY DATE GROUP] // [ℹ] assign "onValue" event-listeners - for (const season_fixture of season_fixture_date_group.fixtures) { + for await (const season_fixture of season_fixture_date_group.fixtures) { if (season_fixture.status == "FT") { continue @@ -47,7 +47,7 @@ export async function getOdds ( const fixture_id = season_fixture.id; - get(child(ref(db_real), 'odds/' + year_ + '/' + new_month_ + '/' + day_ + '/' + fixture_id)) + get(child(ref(db_real), `odds/${year_}/${new_month_}/${day_}/${fixture_id}`)) .then((snapshot) => { if (snapshot.exists()) { const sportbook_array: FIREBASE_odds[] = [] diff --git a/src/lib/firebase/index.ts b/src/lib/firebase/index.ts index dabae9a2b..d088fd83b 100644 --- a/src/lib/firebase/index.ts +++ b/src/lib/firebase/index.ts @@ -53,9 +53,9 @@ export async function getTargetFixtureOdds ( const map = new Map(); let count = 0; // ... iterate over the data of the `lang` in sportbook details; - for (const rankedOdd in sportbook_details) { + for (const rankedOdd of Object.keys(sportbook_details)) { // ... iterate over the data of the fixture avaiable ODDS; - for (const avaiableOdd in fixture_odds_keys) { + for (const avaiableOdd of Object.keys(fixture_odds_keys)) { // ... const targetFixture = fixture_odds_keys[avaiableOdd]; const fixtureOdd = fixture_odds[targetFixture]; diff --git a/src/lib/utils/color_thief.ts b/src/lib/utils/color_thief.ts index 762f27233..c49e93876 100644 --- a/src/lib/utils/color_thief.ts +++ b/src/lib/utils/color_thief.ts @@ -8,6 +8,24 @@ import ColorThief from 'colorthief/dist/color-thief.mjs'; // [ℹ] declaring a new instance of `ColorThief`; const colorThief = new ColorThief(); +/** + * Description: + * ~~~~~~~~~~~~~~~~~~~~ + * A function-method to convert the + * [x,a,c] of RBG values to `#HEX` values + * @param r + * @param g + * @param b + * @returns (# a singel #HEX-Color Value) +*/ +export const rgbToHex = (r, g, b) => + '#' + [r, g, b] + .map((x) => { + const hex = x.toString(16); + return hex.length === 1 ? `0${hex}` : hex; + }) + .join(''); + /** * Description: * ~~~~~~~~~~~~~~~~~~~~ @@ -23,7 +41,7 @@ export function getImageBgColor(imgURL: string, imageVar: string) { // instantiate the image Type; const img = new Image(); // listen, event to wait for the image to load - img.addEventListener('load', function () { + img.addEventListener('load', () => { // get the array of RGB values, const colorValues = colorThief.getColor(img); // convert the RGB values to HEX value, @@ -42,22 +60,4 @@ export function getImageBgColor(imgURL: string, imageVar: string) { catch (e) { if (dev) console.error('-- getImageBgColor() ERR --', e); } -} - -/** - * Description: - * ~~~~~~~~~~~~~~~~~~~~ - * A function-method to convert the - * [x,a,c] of RBG values to `#HEX` values - * @param r - * @param g - * @param b - * @returns (# a singel #HEX-Color Value) -*/ -export const rgbToHex = (r, g, b) => - '#' + [r, g, b] - .map((x) => { - const hex = x.toString(16); - return hex.length === 1 ? '0' + hex : hex; - }) - .join(''); \ No newline at end of file +} \ No newline at end of file diff --git a/src/routes/+page.ts b/src/routes/+page.ts index 58323b46d..76f7c7c8f 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -232,8 +232,8 @@ export async function load ({ // '/api/cache/leagues_table?geoPos='+'en', ]; - const promises = urls.map((url) => - fetch(url) + const promises = urls.map((_url) => + fetch(_url) .then((response) => response.json()) ); diff --git a/src/routes/[lang=lang]/+page.ts b/src/routes/[lang=lang]/+page.ts index 8ea5606b8..7e015f76f 100644 --- a/src/routes/[lang=lang]/+page.ts +++ b/src/routes/[lang=lang]/+page.ts @@ -231,8 +231,8 @@ export async function load ({ // '/api/cache/leagues_table?geoPos='+'en', ]; - const promises = urls.map((url) => - fetch(url) + const promises = urls.map((_url) => + fetch(_url) .then((response) => response.json()) ); diff --git a/src/routes/[lang=lang]/[sport]/[fixture=fixture]/+page.ts b/src/routes/[lang=lang]/[sport]/[fixture=fixture]/+page.ts index b648f15a9..3ea9e1a8a 100644 --- a/src/routes/[lang=lang]/[sport]/[fixture=fixture]/+page.ts +++ b/src/routes/[lang=lang]/[sport]/[fixture=fixture]/+page.ts @@ -374,6 +374,29 @@ export async function load({ * ========== */ + // [🐞] + if (dev) { + console.log('fixture_id: ', fixture_id) + if (response_fixtures_seo == undefined) console.log("response_fixtures_seo is undefined") + if (response_fixtures_page_info == undefined) console.log("response_fixtures_page_info is undefined") + if (response_scoreboard == undefined) console.log("response_scoreboard is undefined") + if (response_scoreboard_translation == undefined) console.log("response_scoreboard_translation is undefined") + if (response_lineups == undefined) console.log("response_lineups is undefined") + if (response_lineups_translation == undefined) console.log("response_lineups_translation is undefined") + if (response_incidents == undefined) console.log("response_incidents is undefined") + if (response_incidents_translation == undefined) console.log("response_incidents_translation is undefined") + if (response_featured_betting_sites_translation == undefined) console.log("response_featured_betting_sites_translation is undefined") + if (response_statistics == undefined) console.log("response_statistics is undefined") + if (response_statistics_translation == undefined) console.log("response_statistics_translation is undefined") + if (response_content == undefined) console.log("response_content is undefined") + if (response_content_translation == undefined) console.log("response_content_translation is undefined") + if (response_about_translation == undefined) console.log("response_about_translation is undefined") + if (response_votes_translation == undefined) console.log("response_votes_translation is undefined") + if (response_h2h == undefined) console.log("response_h2h is undefined") + if (response_h2h_translation == undefined) console.log("response_h2h_translation is undefined") + if (response_fixtures_odds_translations == undefined) console.log("response_fixtures_odds_translations is undefined") + } + if ( response_fixtures_seo && response_fixtures_page_info @@ -392,7 +415,7 @@ export async function load({ && response_about_translation && response_votes_translation && response_probability_translation - && response_h2h + // && response_h2h // IMPORTANT can be "NULL" && response_h2h_translation // extra && response_fixtures_odds_translations diff --git a/src/routes/[sport]/[fixture=fixture]/+page.ts b/src/routes/[sport]/[fixture=fixture]/+page.ts index b648f15a9..3ea9e1a8a 100644 --- a/src/routes/[sport]/[fixture=fixture]/+page.ts +++ b/src/routes/[sport]/[fixture=fixture]/+page.ts @@ -374,6 +374,29 @@ export async function load({ * ========== */ + // [🐞] + if (dev) { + console.log('fixture_id: ', fixture_id) + if (response_fixtures_seo == undefined) console.log("response_fixtures_seo is undefined") + if (response_fixtures_page_info == undefined) console.log("response_fixtures_page_info is undefined") + if (response_scoreboard == undefined) console.log("response_scoreboard is undefined") + if (response_scoreboard_translation == undefined) console.log("response_scoreboard_translation is undefined") + if (response_lineups == undefined) console.log("response_lineups is undefined") + if (response_lineups_translation == undefined) console.log("response_lineups_translation is undefined") + if (response_incidents == undefined) console.log("response_incidents is undefined") + if (response_incidents_translation == undefined) console.log("response_incidents_translation is undefined") + if (response_featured_betting_sites_translation == undefined) console.log("response_featured_betting_sites_translation is undefined") + if (response_statistics == undefined) console.log("response_statistics is undefined") + if (response_statistics_translation == undefined) console.log("response_statistics_translation is undefined") + if (response_content == undefined) console.log("response_content is undefined") + if (response_content_translation == undefined) console.log("response_content_translation is undefined") + if (response_about_translation == undefined) console.log("response_about_translation is undefined") + if (response_votes_translation == undefined) console.log("response_votes_translation is undefined") + if (response_h2h == undefined) console.log("response_h2h is undefined") + if (response_h2h_translation == undefined) console.log("response_h2h_translation is undefined") + if (response_fixtures_odds_translations == undefined) console.log("response_fixtures_odds_translations is undefined") + } + if ( response_fixtures_seo && response_fixtures_page_info @@ -392,7 +415,7 @@ export async function load({ && response_about_translation && response_votes_translation && response_probability_translation - && response_h2h + // && response_h2h // IMPORTANT can be "NULL" && response_h2h_translation // extra && response_fixtures_odds_translations diff --git a/src/routes/api/hasura/fixtures/head-2-head/+server.ts b/src/routes/api/hasura/fixtures/head-2-head/+server.ts index 94edb31ad..ad8eb1c1d 100644 --- a/src/routes/api/hasura/fixtures/head-2-head/+server.ts +++ b/src/routes/api/hasura/fixtures/head-2-head/+server.ts @@ -163,13 +163,13 @@ async function main ( { team_logo: team_1_data?.data?.logo_path, team_name: team_1_data?.data?.name, - team_short: team_1_data?.data?.short_code, + team_short: team_1_data?.data?.short_code || team_1_data?.data?.name.slice(0, 3).toUpperCase() || null, team_id: team_ids_arr[0], }, { team_logo: team_2_data?.data?.logo_path, team_name: team_2_data?.data?.name, - team_short: team_2_data?.data?.short_code, + team_short: team_2_data?.data?.short_code || team_2_data?.data?.name.slice(0, 3).toUpperCase() || null, team_id: team_ids_arr[1], } ], diff --git a/src/routes/api/hasura/fixtures/lineups/+server.ts b/src/routes/api/hasura/fixtures/lineups/+server.ts index 15ad97dfa..06f37ad68 100644 --- a/src/routes/api/hasura/fixtures/lineups/+server.ts +++ b/src/routes/api/hasura/fixtures/lineups/+server.ts @@ -423,7 +423,7 @@ async function get_target_player_data ( playerIdsArr: number[] ): Promise < BETARENA_HASURA_SURGICAL_JSONB_scores_football_players[] > { - playerIdsArr = playerIdsArr.filter(function (el) { + playerIdsArr = playerIdsArr.filter((el) => { return el != undefined; });