-
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 #137 from game-node-app/dev
PSN integration work
- Loading branch information
Showing
47 changed files
with
623 additions
and
410 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
export enum EConnectionType { | ||
Steam = "steam", | ||
STEAM = "steam", | ||
PSN = "psn", | ||
} | ||
|
||
export const IMPORTER_VIABLE_CONNECTIONS = [EConnectionType.Steam]; | ||
export const IMPORTER_VIABLE_CONNECTIONS = [ | ||
EConnectionType.STEAM, | ||
EConnectionType.PSN, | ||
]; | ||
|
||
export const IMPORTER_WATCH_VIABLE_CONNECTIONS = [ | ||
EConnectionType.STEAM, | ||
EConnectionType.PSN, | ||
]; |
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,4 @@ | ||
export class ConnectionUserResolveDto { | ||
userId: string; | ||
username: string; | ||
} |
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,7 @@ | ||
import { UserConnection } from "../entity/user-connection.entity"; | ||
import { OmitType } from "@nestjs/swagger"; | ||
|
||
export class UserConnectionDto extends OmitType(UserConnection, ["profile"]) { | ||
isImporterViable: boolean; | ||
isImporterWatchViable: boolean; | ||
} |
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,79 @@ | ||
import { Inject, Injectable, Logger } from "@nestjs/common"; | ||
import { CACHE_MANAGER, Cache } from "@nestjs/cache-manager"; | ||
import { FindManyOptions, FindOneOptions, Repository } from "typeorm"; | ||
import { Game } from "./entities/game.entity"; | ||
import { InjectRepository } from "@nestjs/typeorm"; | ||
import { minutes } from "@nestjs/throttler"; | ||
import { TPaginationData } from "../../utils/pagination/pagination-response.dto"; | ||
|
||
/** | ||
* Adds a cache layer for calls to game's entity repository <br> | ||
* Necessary because TypeORM's cache tend to miss. | ||
* @param options | ||
* @param ttl | ||
*/ | ||
@Injectable() | ||
export class GameRepositoryCacheService { | ||
private readonly logger = new Logger(GameRepositoryCacheService.name); | ||
|
||
constructor( | ||
@InjectRepository(Game) | ||
private readonly gameRepository: Repository<Game>, | ||
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache, | ||
) {} | ||
|
||
async find( | ||
options: Omit<FindManyOptions<Game>, "cache">, | ||
ttl: number = minutes(5), | ||
) { | ||
const cacheKey = JSON.stringify(options); | ||
const itemsInCache = await this.cacheManager.get<Game[]>(cacheKey); | ||
|
||
if (itemsInCache) return itemsInCache; | ||
|
||
const items = await this.gameRepository.find(options); | ||
|
||
this.cacheManager.set(cacheKey, items, ttl).catch((err) => { | ||
this.logger.error(err); | ||
}); | ||
|
||
return items; | ||
} | ||
|
||
async findAndCount( | ||
options: Omit<FindManyOptions<Game>, "cache">, | ||
ttl: number = minutes(5), | ||
) { | ||
const cacheKey = JSON.stringify(options); | ||
const itemsInCache = | ||
await this.cacheManager.get<TPaginationData<Game>>(cacheKey); | ||
|
||
if (itemsInCache) return itemsInCache; | ||
|
||
const items = await this.gameRepository.findAndCount(options); | ||
|
||
this.cacheManager.set(cacheKey, items, ttl).catch((err) => { | ||
this.logger.error(err); | ||
}); | ||
|
||
return items; | ||
} | ||
|
||
async findOne( | ||
options: Omit<FindOneOptions<Game>, "cache">, | ||
ttl: number = minutes(1), | ||
) { | ||
const cacheKey = JSON.stringify(options); | ||
const itemInCache = await this.cacheManager.get<Game>(cacheKey); | ||
|
||
if (itemInCache) return itemInCache; | ||
|
||
const items = await this.gameRepository.findOne(options); | ||
|
||
this.cacheManager.set(cacheKey, items, ttl).catch((err) => { | ||
this.logger.error(err); | ||
}); | ||
|
||
return items; | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
src/game/game-repository/game-repository.controller.spec.ts
This file was deleted.
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
Oops, something went wrong.