Skip to content

Commit

Permalink
fix: added provider filter for quering lines
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueSCar committed Aug 20, 2024
1 parent ae069ad commit fe6af67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/app/lines/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class BettingController extends Controller {
* @param home Optional home team filter
* @param away Optional away team filter
* @param conference Optional conference filter
* @param provider Optional provider name filter
* @isInt gameId
* @isInt year
* @isInt week
Expand All @@ -33,6 +34,7 @@ export class BettingController extends Controller {
@Query() home?: string,
@Query() away?: string,
@Query() conference?: string,
@Query() provider?: string,
): Promise<BettingGame[]> {
return await getLines(
gameId,
Expand All @@ -43,6 +45,7 @@ export class BettingController extends Controller {
home,
away,
conference,
provider,
);
}
}
15 changes: 13 additions & 2 deletions src/app/lines/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidateError } from 'tsoa';
import { kdb } from '../../config/database';
import { SeasonType } from '../enums';
import { DivisionClassification, SeasonType } from '../enums';
import { BettingGame, GameLine } from './types';

export const getLines = async (
Expand All @@ -12,6 +12,7 @@ export const getLines = async (
home?: string,
away?: string,
conference?: string,
provider?: string,
): Promise<BettingGame[]> => {
if (!year && !gameId) {
throw new ValidateError(
Expand Down Expand Up @@ -66,9 +67,11 @@ export const getLines = async (
'game.startDate',
'ht.school as homeSchool',
'hc.name as homeConference',
'hc.division as homeClassification',
'hgt.points as homeScore',
'awt.school as awaySchool',
'ac.name as awayConference',
'ac.division as awayClassification',
'agt.points as awayScore',
'linesProvider.name',
'gameLines.spread',
Expand Down Expand Up @@ -131,6 +134,10 @@ export const getLines = async (
}
}

if (provider) {
gamesQuery = gamesQuery.where((eb) => eb(eb.fn('lower', ['linesProvider.name']), '=', provider.toLowerCase()));
}

const games = await gamesQuery.execute();

const gameIds = Array.from(new Set(games.map((g) => g.id)));
Expand Down Expand Up @@ -171,13 +178,17 @@ export const getLines = async (
startDate: g.startDate,
homeTeam: g.homeSchool,
homeConference: g.homeConference,
// @ts-ignore
homeClassification: g.homeClassification,
homeScore: g.homeScore,
awayTeam: g.awaySchool,
awayConference: g.awayConference,
// @ts-ignore
awayClassification: g.awayClassification,
awayScore: g.awayScore,
lines: gameLines,
};
});

return results;
return results.filter((r) => r.lines.length > 0 || r.homeClassification === DivisionClassification.FBS || r.awayClassification === DivisionClassification.FBS);
};
4 changes: 3 additions & 1 deletion src/app/lines/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SeasonType } from '../enums';
import { DivisionClassification, SeasonType } from '../enums';

export interface BettingGame {
/**
Expand All @@ -20,12 +20,14 @@ export interface BettingGame {
startDate: Date;
homeTeam: string;
homeConference: string | null;
homeClassification: DivisionClassification | null;
/**
* @isInt
*/
homeScore: number | null;
awayTeam: string;
awayConference: string | null;
awayClassification: DivisionClassification | null;
/**
* @isInt
*/
Expand Down

0 comments on commit fe6af67

Please sign in to comment.