refactor(server): introduce scoped query builders for recurring filters

This commit is contained in:
Julian Tölle 2020-07-12 14:47:32 +02:00
parent 1b03bacb7b
commit 11af91cadb
3 changed files with 41 additions and 23 deletions

View file

@ -112,14 +112,10 @@ export class ReportsService {
customTimeEnd,
});
const getArtistsWithCountQB = this.listenRepository
.createQueryBuilder("l")
.andWhere('l."userId" = :userID', { userID: user.id })
.andWhere("l.playedAt BETWEEN :timeStart AND :timeEnd", {
timeStart: interval.start,
timeEnd: interval.end,
})
.leftJoin("l.track", "track")
const getArtistsWithCountQB = this.listenRepository.scoped
.byUser(user)
.duringInterval(interval)
.leftJoin("listen.track", "track")
.leftJoinAndSelect("track.artists", "artists")
.groupBy("artists.id")
.select("artists.*")