refactor(server): do not export listen repository to outside modules

This commit is contained in:
Julian Tölle 2020-07-12 15:00:02 +02:00
parent 11af91cadb
commit ad0d197105
3 changed files with 9 additions and 8 deletions

View file

@ -7,7 +7,7 @@ import { ListensService } from "./listens.service";
@Module({
imports: [TypeOrmModule.forFeature([ListenRepository])],
providers: [ListensService],
exports: [ListensService, TypeOrmModule],
exports: [ListensService],
controllers: [ListensController],
})
export class ListensModule {}

View file

@ -8,7 +8,7 @@ import {
import { CreateListenDto } from "./dto/create-listen.dto";
import { GetListensDto } from "./dto/get-listens.dto";
import { Listen } from "./listen.entity";
import { ListenRepository } from "./listen.repository";
import { ListenRepository, ListenScopes } from "./listen.repository";
@Injectable()
export class ListensService {
@ -64,4 +64,8 @@ export class ListensService {
limit,
});
}
getScopedQueryBuilder(): ListenScopes {
return this.listenRepository.scoped;
}
}

View file

@ -15,7 +15,6 @@ import {
startOfDay,
sub,
} from "date-fns";
import { ListenRepository } from "../listens/listen.repository";
import { ListensService } from "../listens/listens.service";
import { GetListenReportDto } from "./dto/get-listen-report.dto";
import { GetTopArtistsReportDto } from "./dto/get-top-artists-report.dto";
@ -63,10 +62,7 @@ const PAGINATION_LIMIT_UNLIMITED = 10000000;
@Injectable()
export class ReportsService {
constructor(
private readonly listensService: ListensService,
private readonly listenRepository: ListenRepository
) {}
constructor(private readonly listensService: ListensService) {}
async getListens(options: GetListenReportDto): Promise<ListenReportDto> {
const { user, timeFrame, timeStart, timeEnd } = options;
@ -112,7 +108,8 @@ export class ReportsService {
customTimeEnd,
});
const getArtistsWithCountQB = this.listenRepository.scoped
const getArtistsWithCountQB = this.listensService
.getScopedQueryBuilder()
.byUser(user)
.duringInterval(interval)
.leftJoin("listen.track", "track")