mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
refator: use TimeOptions for TopArtists report
This commit is contained in:
parent
ad0d197105
commit
5bc76f23d0
9 changed files with 62 additions and 46 deletions
|
|
@ -1,18 +1,10 @@
|
|||
import { IsEnum, IsISO8601, ValidateIf } from "class-validator";
|
||||
import { ValidateNested } from "class-validator";
|
||||
import { User } from "../../users/user.entity";
|
||||
import { TimePreset } from "../timePreset.enum";
|
||||
import { ReportTimeDto } from "./report-time.dto";
|
||||
|
||||
export class GetTopArtistsReportDto {
|
||||
user: User;
|
||||
|
||||
@IsEnum(TimePreset)
|
||||
timePreset: TimePreset;
|
||||
|
||||
@ValidateIf((o) => o.timePreset === TimePreset.CUSTOM)
|
||||
@IsISO8601()
|
||||
customTimeStart: string;
|
||||
|
||||
@ValidateIf((o) => o.timePreset === TimePreset.CUSTOM)
|
||||
@IsISO8601()
|
||||
customTimeEnd: string;
|
||||
@ValidateNested()
|
||||
time: ReportTimeDto;
|
||||
}
|
||||
|
|
|
|||
15
src/reports/dto/report-time.dto.ts
Normal file
15
src/reports/dto/report-time.dto.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { IsEnum, IsISO8601, ValidateIf } from "class-validator";
|
||||
import { TimePreset } from "../timePreset.enum";
|
||||
|
||||
export class ReportTimeDto {
|
||||
@IsEnum(TimePreset)
|
||||
timePreset: TimePreset;
|
||||
|
||||
@ValidateIf((o) => o.timePreset === TimePreset.CUSTOM)
|
||||
@IsISO8601()
|
||||
customTimeStart: string;
|
||||
|
||||
@ValidateIf((o) => o.timePreset === TimePreset.CUSTOM)
|
||||
@IsISO8601()
|
||||
customTimeEnd: string;
|
||||
}
|
||||
|
|
@ -24,9 +24,9 @@ export class ReportsController {
|
|||
@Get("top-artists")
|
||||
@Auth()
|
||||
async getTopArtists(
|
||||
@Query() options: Omit<GetTopArtistsReportDto, "user">,
|
||||
@Query() time: ReportTimeDto,
|
||||
@ReqUser() user: User
|
||||
): Promise<TopArtistsReportDto> {
|
||||
return this.reportsService.getTopArtists({ ...options, user });
|
||||
return this.reportsService.getTopArtists({ user, time });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,13 +100,9 @@ export class ReportsService {
|
|||
async getTopArtists(
|
||||
options: GetTopArtistsReportDto
|
||||
): Promise<TopArtistsReportDto> {
|
||||
const { user, timePreset, customTimeStart, customTimeEnd } = options;
|
||||
const { user, time: timePreset } = options;
|
||||
|
||||
const interval = this.getIntervalFromPreset({
|
||||
timePreset,
|
||||
customTimeStart,
|
||||
customTimeEnd,
|
||||
});
|
||||
const interval = this.getIntervalFromPreset(timePreset);
|
||||
|
||||
const getArtistsWithCountQB = this.listensService
|
||||
.getScopedQueryBuilder()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue