Cast string to interval correctly

This commit is contained in:
Brian Beck 2021-09-26 00:46:51 -07:00
parent edd3076b54
commit 3114913c85

View file

@ -103,7 +103,7 @@ export class PlayersService {
// Cast to float to avoid integer division truncating the result. // Cast to float to avoid integer division truncating the result.
const aggregatedAccuracy = `(${aggregatedHits}::float / ${aggregatedShots}::float)`; const aggregatedAccuracy = `(${aggregatedHits}::float / ${aggregatedShots}::float)`;
const sinceDate = '(now() - interval :timePeriod)'; const sinceDate = '(now() - (:timePeriod)::interval)';
// TODO: This whole query could probably be turned into a `ViewEntity` at // TODO: This whole query could probably be turned into a `ViewEntity` at
// some point, but I couldn't get that to work. // some point, but I couldn't get that to work.
@ -208,7 +208,7 @@ export class PlayersService {
async findTopWins(topWinsQuery: TopWinsQueryDto) { async findTopWins(topWinsQuery: TopWinsQueryDto) {
const { minGames, limit, timePeriod } = topWinsQuery; const { minGames, limit, timePeriod } = topWinsQuery;
const sinceDate = '(now() - interval :timePeriod)'; const sinceDate = '(now() - (:timePeriod)::interval)';
const query = this.playersRepository const query = this.playersRepository
.createQueryBuilder('player') .createQueryBuilder('player')