-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start working on database binding for storing game events from bet pr…
…oviders
- Loading branch information
1 parent
60ab526
commit 802133c
Showing
7 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
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,82 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn, Index} from "typeorm"; | ||
|
||
/** | ||
* Table representing game events where there is no possibility of a draw. | ||
* A good example is tennis. | ||
*/ | ||
@Entity({name: "two_way_game_event"}) | ||
export class TwoWayGameEventEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Index("two_way_game_event_provider_id_idx") | ||
@Column("string", {length: 100, nullable: false}) | ||
bet_provider_id: string | ||
|
||
@Column("varchar", {length: 100, nullable: false}) | ||
club_a: string | ||
|
||
@Column("varchar", {length: 100, nullable: false}) | ||
club_b: string | ||
|
||
@Column("decimal", {nullable: false}) | ||
odds_a_win: number | ||
|
||
@Column("decimal", {nullable: false}) | ||
odds_b_win: number | ||
|
||
@Column("varchar", {length: 100, nullable: false}) | ||
bet_provider_name: string | ||
|
||
@Column("varchar", {length: 100, nullable: false}) | ||
game_name: string | ||
|
||
@Index("two_way_game_event_created_at_idx") | ||
@Column("timestamptz", {nullable: false, default: () => "CURRENT_TIMESTAMP"}) | ||
created_at_utc: Date | ||
|
||
@Column("timestamptz", {nullable: false, default: () => "CURRENT_TIMESTAMP", onUpdate: "CURRENT_TIMESTAMP"}) | ||
updated_at_utc: Date | ||
} | ||
|
||
/** | ||
* Table representing game events where the is possibility of a draw. A great | ||
* example is football. | ||
*/ | ||
@Entity({name: "three_way_game_event"}) | ||
export class ThreeWayGameEventEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Index("three_way_game_event_provider_id_idx") | ||
@Column("string", {length: 100, nullable: false}) | ||
bet_provider_id: string | ||
|
||
@Column("varchar", {length: 100, nullable: false}) | ||
club_a: string | ||
|
||
@Column("varchar", {length: 100, nullable: false}) | ||
club_b: string | ||
|
||
@Column("decimal", {nullable: false}) | ||
odds_a_win: number | ||
|
||
@Column("decimal", {nullable: false}) | ||
odds_b_win: number | ||
|
||
@Column("decimal", {nullable: false}) | ||
odds_draw: number | ||
|
||
@Column("varchar", {length: 100, nullable: false}) | ||
bet_provider: string | ||
|
||
@Column("varchar", {length: 100, nullable: false}) | ||
game_name: string | ||
|
||
@Index("three_way_game_event_created_at_idx") | ||
@Column("timestamptz", {nullable: false, default: () => "CURRENT_TIMESTAMP"}) | ||
created_at_utc: Date | ||
|
||
@Column("timestamptz", {nullable: false, default: () => "CURRENT_TIMESTAMP", onUpdate: "CURRENT_TIMESTAMP"}) | ||
updated_at_utc: Date | ||
} |
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,43 @@ | ||
import {DataSource} from "typeorm"; | ||
import { ThreeWayGameEvent, TwoWayGameEvent } from "../../../utils/types/db"; | ||
import { ThreeWayGameEventEntity, TwoWayGameEventEntity } from "../entities"; | ||
|
||
export const insertTwoWayGameEvent = async ( | ||
dataSource: DataSource, | ||
data: TwoWayGameEvent | ||
) => { | ||
const toDataBase = { | ||
bet_provider_id: data.betProviderId, | ||
bet_provider_name: data.betProviderName, | ||
club_a: data.clubA, | ||
club_b: data.clubB, | ||
odds_a_win: data.oddsAWin, | ||
odds_b_win: data.oddsBWin, | ||
game_name: data.gameName | ||
}; | ||
await dataSource.createQueryBuilder() | ||
.insert() | ||
.into(TwoWayGameEventEntity) | ||
.values(toDataBase) | ||
.execute(); | ||
}; | ||
|
||
export const insertThreeWayGameEvent = async ( | ||
dataSource: DataSource, | ||
data: ThreeWayGameEvent | ||
) => { | ||
const toDataBase = { | ||
bet_provider_id: data.betProviderId, | ||
bet_provider_name: data.betProviderName, | ||
club_a: data.clubA, | ||
club_b: data.clubB, | ||
odds_a_win: data.oddsAWin, | ||
odds_b_win: data.oddsBWin, | ||
game_name: data.gameName | ||
} | ||
await dataSource.createQueryBuilder() | ||
.insert() | ||
.into(ThreeWayGameEventEntity) | ||
.values(toDataBase) | ||
.execute(); | ||
}; |
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
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
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
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,28 @@ | ||
/** | ||
* File contains data types for to be used to inert new data to the database. | ||
* For reading data off the database, we'll make use of the entity itself as | ||
* it has more meta data i.e insert_id, created/updated at. | ||
*/ | ||
|
||
import { BetProviders, Games } from "../common"; | ||
|
||
export interface TwoWayGameEvent { | ||
betProviderName: BetProviders; | ||
betProviderId: string; | ||
clubA: string; | ||
clubB: string; | ||
oddsAWin: number; | ||
oddsBWin: number; | ||
gameName: Games; | ||
} | ||
|
||
export interface ThreeWayGameEvent { | ||
betProviderName: BetProviders; | ||
betProviderId: string; | ||
clubA: string; | ||
clubB: string; | ||
oddsAWin: number; | ||
oddsBWin: number; | ||
oddsDraw: number; | ||
gameName: Games; | ||
} |
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