-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from game-node-app/dev
Dev
- Loading branch information
Showing
32 changed files
with
562 additions
and
86 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IsIn, IsNotEmpty } from "class-validator"; | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
|
||
export type ProfileImageIdentifier = "avatar" | "banner"; | ||
|
||
export class UpdateProfileImageDto { | ||
file: any; | ||
@ApiProperty({ | ||
type: "string", | ||
}) | ||
@IsNotEmpty() | ||
@IsIn(["avatar", "banner"]) | ||
type: ProfileImageIdentifier; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
CreateDateColumn, | ||
Entity, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from "typeorm"; | ||
import { PersistedImageDetails } from "../../utils/persisted-image-details.entity"; | ||
import { Profile } from "./profile.entity"; | ||
|
||
@Entity() | ||
export class ProfileBanner extends PersistedImageDetails { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
@OneToOne(() => Profile, (profile) => profile.avatar) | ||
profile: Profile; | ||
@CreateDateColumn() | ||
createdAt: Date; | ||
@UpdateDateColumn() | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/profile/profile-statistics/dto/profile-metrics-distribution.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { IsEnum, IsNotEmpty } from "class-validator"; | ||
|
||
export enum ProfileMetricsDistribution { | ||
RELEASE_YEAR = "release_year", | ||
FINISH_YEAR = "finish_year", | ||
} | ||
|
||
export class ProfileMetricsDistributionRequestDto { | ||
@IsNotEmpty() | ||
@IsEnum(ProfileMetricsDistribution) | ||
by: ProfileMetricsDistribution; | ||
} | ||
|
||
/** | ||
* Relation between a year (presented as string) and data for said period. | ||
*/ | ||
export interface ProfileMetricsDistributionYearToData { | ||
[p: string]: { | ||
count: number; | ||
totalEstimatedPlaytime: number; | ||
}; | ||
} | ||
|
||
export class ProfileMetricsDistributionResponseDto { | ||
distribution: ProfileMetricsDistributionYearToData; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/profile/profile-statistics/dto/profile-metrics-overview.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class ProfileMetricsOverviewDto { | ||
totalGames: number; | ||
totalCollections: number; | ||
totalFinishedGames: number; | ||
/** | ||
* Total playtime spent on finished games, based on available data and HLTB's 'main' profile. | ||
*/ | ||
totalEstimatedPlaytime: number; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/profile/profile-statistics/profile-metrics.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Controller, Get, Param, Query, UseGuards } from "@nestjs/common"; | ||
import { ApiOkResponse, ApiTags } from "@nestjs/swagger"; | ||
import { ProfileMetricsService } from "./profile-metrics.service"; | ||
import { ProfileMetricsOverviewDto } from "./dto/profile-metrics-overview.dto"; | ||
import { AuthGuard } from "../../auth/auth.guard"; | ||
import { Public } from "../../auth/public.decorator"; | ||
import { | ||
ProfileMetricsDistributionRequestDto, | ||
ProfileMetricsDistributionResponseDto, | ||
} from "./dto/profile-metrics-distribution.dto"; | ||
|
||
@Controller("profile/metrics") | ||
@ApiTags("profile-metrics") | ||
@UseGuards(AuthGuard) | ||
export class ProfileMetricsController { | ||
constructor( | ||
private readonly profileStatisticsService: ProfileMetricsService, | ||
) {} | ||
|
||
/** | ||
* Retrieves basic stats for a user profile | ||
* @see | ||
*/ | ||
@Get("overview/:userId") | ||
@ApiOkResponse({ | ||
type: ProfileMetricsOverviewDto, | ||
}) | ||
@Public() | ||
async getStatsOverview(@Param("userId") userId: string) { | ||
return this.profileStatisticsService.getStatsOverview(userId); | ||
} | ||
|
||
@Get("distribution/:userId") | ||
@ApiOkResponse({ | ||
type: ProfileMetricsDistributionResponseDto, | ||
}) | ||
async getStatsDistribution( | ||
@Param("userId") userId: string, | ||
@Query() dto: ProfileMetricsDistributionRequestDto, | ||
) { | ||
return this.profileStatisticsService.getDistribution(userId, dto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { ProfileMetricsController } from "./profile-metrics.controller"; | ||
import { ProfileMetricsService } from "./profile-metrics.service"; | ||
import { CollectionsEntriesModule } from "../../collections/collections-entries/collections-entries.module"; | ||
import { CollectionsModule } from "../../collections/collections.module"; | ||
import { HltbSyncModule } from "../../sync/hltb/hltb-sync.module"; | ||
import { GameRepositoryModule } from "../../game/game-repository/game-repository.module"; | ||
|
||
@Module({ | ||
imports: [ | ||
CollectionsModule, | ||
CollectionsEntriesModule, | ||
HltbSyncModule, | ||
GameRepositoryModule, | ||
], | ||
controllers: [ProfileMetricsController], | ||
providers: [ProfileMetricsService], | ||
}) | ||
export class ProfileMetricsModule {} |
Oops, something went wrong.