-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move components to models/ folder, add gameweek model, remove f…
…ixtures model
- Loading branch information
Showing
12 changed files
with
557 additions
and
76 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './user' | ||
export * from './fpl' | ||
export * from './player' | ||
export * from './fixture' | ||
export * from './fixtures' | ||
export * from './models/user' | ||
export * from './models/fpl' | ||
export * from './models/player' | ||
export * from './models/fixture' | ||
export * from './models/gameweek' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import FPL from './fpl' | ||
|
||
export class ClassicLeague extends FPL {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
import FPL from './fpl' | ||
import { API_URLS } from '../constants' | ||
import { | ||
FixtureDelegate, | ||
FixturesRespDelegate, | ||
FixStatsItemDelegate, | ||
} from '../types' | ||
|
||
export class Fixture extends FPL { | ||
id: number | ||
constructor(id: number) { | ||
super() | ||
this.id = id | ||
// TODO: Fetch Fixture on default call | ||
} | ||
public async getDetails(): Promise<FixtureDelegate | null> { | ||
let fixture = null | ||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((elem) => { | ||
if (elem.id == this.id) { | ||
fixture = elem | ||
} | ||
}) | ||
return fixture | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
|
||
// TODO: Replace forEach with above function | ||
public async getAssisters(): Promise<FixStatsItemDelegate> { | ||
let assisters: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'assists') { | ||
delete elem.identifier | ||
assisters = elem | ||
} | ||
}) | ||
}) | ||
return assisters | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
|
||
public async getBonus(): Promise<FixStatsItemDelegate> { | ||
let bonus: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'bonus') { | ||
delete elem.identifier | ||
bonus = elem | ||
} | ||
}) | ||
}) | ||
return bonus | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
|
||
public async getBPS(): Promise<FixStatsItemDelegate> { | ||
let bps: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'bps') { | ||
delete elem.identifier | ||
bps = elem | ||
} | ||
}) | ||
}) | ||
return bps | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
|
||
public async getGoalscorers(): Promise<FixStatsItemDelegate> { | ||
let goalscorers: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'goals_scored') { | ||
delete elem.identifier | ||
goalscorers = elem | ||
} | ||
}) | ||
}) | ||
return goalscorers | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
public async getOwnGoalscorers(): Promise<FixStatsItemDelegate> { | ||
let owngoals: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'own_goals') { | ||
delete elem.identifier | ||
owngoals = elem | ||
} | ||
}) | ||
}) | ||
return owngoals | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
public async getPenaltyMisses(): Promise<FixStatsItemDelegate> { | ||
let missedpenalties: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'penalties_missed') { | ||
delete elem.identifier | ||
missedpenalties = elem | ||
} | ||
}) | ||
}) | ||
return missedpenalties | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
public async getPenaltySaves(): Promise<FixStatsItemDelegate> { | ||
let savedpenalties: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'penalties_saved') { | ||
delete elem.identifier | ||
savedpenalties = elem | ||
} | ||
}) | ||
}) | ||
return savedpenalties | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
public async getRedCards(): Promise<FixStatsItemDelegate> { | ||
let redcards: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'red_cards') { | ||
delete elem.identifier | ||
redcards = elem | ||
} | ||
}) | ||
}) | ||
return redcards | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
public async getYellowCards(): Promise<FixStatsItemDelegate> { | ||
let yellowcards: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'yellow_cards') { | ||
delete elem.identifier | ||
yellowcards = elem | ||
} | ||
}) | ||
}) | ||
return yellowcards | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
public async getSaves(): Promise<FixStatsItemDelegate> { | ||
let saves: FixStatsItemDelegate = { | ||
a: [], | ||
h: [], | ||
} | ||
|
||
try { | ||
const { data }: FixturesRespDelegate = await this.fetchAPI( | ||
API_URLS.FIXTURES, | ||
) | ||
data.forEach((fixture) => { | ||
fixture.stats.forEach((elem) => { | ||
if (elem.identifier === 'saves') { | ||
delete elem.identifier | ||
saves = elem | ||
} | ||
}) | ||
}) | ||
return saves | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.