diff --git a/src/datastores/postgres/entities/index.ts b/src/datastores/postgres/entities/index.ts new file mode 100644 index 0000000..45592b6 --- /dev/null +++ b/src/datastores/postgres/entities/index.ts @@ -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 +} \ No newline at end of file diff --git a/src/datastores/postgres/queries/index.ts b/src/datastores/postgres/queries/index.ts new file mode 100644 index 0000000..3897c4a --- /dev/null +++ b/src/datastores/postgres/queries/index.ts @@ -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(); +}; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 1e6bcf1..29afce4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import * as path from "path"; - +import "reflect-metadata"; import "dotenv/config"; import {ILogObj, Logger} from "tslog"; diff --git a/src/utils/redis/index.ts b/src/utils/redis/index.ts index c75242e..2fd7851 100644 --- a/src/utils/redis/index.ts +++ b/src/utils/redis/index.ts @@ -9,5 +9,9 @@ import { BetProviderGameConfig } from "../types/common"; * @returns Channel name based on bet provider, game name and bet type. An example generated value is BETIKA_TennisSingles_TwoWay */ export function getRedisHtmlParserChannelName(betProvider: BetProvider, gameConfig: BetProviderGameConfig): string { - return `${betProvider.name}_${gameConfig.name.replace(" ", "")}_${gameConfig.betType.replace(" ", "")}` + return `${betProvider.name}_${gameConfig.name.replace(" ", "")}_${gameConfig.betType.replace(" ", "")}`; +} + +export function getRedisEventsChannelName(betProvider: BetProvider, gameConfig: BetProviderGameConfig): string { + return `event:${betProvider.name}_${gameConfig.name.replace(" ", "")}_${gameConfig.betType.replace(" ", "")}`; } diff --git a/src/utils/types/common/index.ts b/src/utils/types/common/index.ts index 28a12d4..1fb19cc 100644 --- a/src/utils/types/common/index.ts +++ b/src/utils/types/common/index.ts @@ -58,3 +58,8 @@ export enum TimeZones { UTC = "UTC", NAIROBI = "Africa/Nairobi" } + +// TODO: Work on adding this in the future +export enum GameStatus { + +} diff --git a/src/utils/types/db/index.ts b/src/utils/types/db/index.ts new file mode 100644 index 0000000..9d8909e --- /dev/null +++ b/src/utils/types/db/index.ts @@ -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; +} diff --git a/tsconfig.json b/tsconfig.json index c394abb..ad8d262 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -87,7 +87,7 @@ "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + "strictPropertyInitialization": false, /* Check for class properties that are declared but not set in the constructor. */ "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */