-
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 #139 from game-node-app/dev
Tidying up Importer system for PSN
- Loading branch information
Showing
10 changed files
with
162 additions
and
53 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/game/game-repository/external-game/external-game.service.spec.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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ExternalGameService } from './external-game.service'; | ||
|
||
describe('ExternalGameService', () => { | ||
let service: ExternalGameService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ExternalGameService], | ||
}).compile(); | ||
|
||
service = module.get<ExternalGameService>(ExternalGameService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
src/game/game-repository/external-game/external-game.service.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,64 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { InjectRepository } from "@nestjs/typeorm"; | ||
import { GameExternalGame } from "../entities/game-external-game.entity"; | ||
import { In, Repository } from "typeorm"; | ||
import { days } from "@nestjs/throttler"; | ||
import { EGameExternalGameCategory } from "../game-repository.constants"; | ||
import { toMap } from "../../../utils/toMap"; | ||
import { Game } from "../entities/game.entity"; | ||
|
||
@Injectable() | ||
export class ExternalGameService { | ||
constructor( | ||
@InjectRepository(GameExternalGame) | ||
private readonly gameExternalGameRepository: Repository<GameExternalGame>, | ||
) {} | ||
|
||
private reOrderBySourceIds( | ||
originalIds: string[], | ||
unOrderedGames: GameExternalGame[], | ||
) { | ||
const gamesMap = toMap(unOrderedGames, "uid"); | ||
|
||
return originalIds | ||
.map((id) => { | ||
return gamesMap.get(id); | ||
}) | ||
.filter((game) => game != undefined) as GameExternalGame[]; | ||
} | ||
|
||
async getExternalGamesForGameIds(gameIds: number[]) { | ||
return this.gameExternalGameRepository.find({ | ||
where: { | ||
gameId: In(gameIds), | ||
}, | ||
cache: { | ||
id: `external-games-ids-${gameIds}`, | ||
milliseconds: days(1), | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* Returns a list of GameExternalGame for each sourceId (referred to as uid) | ||
* @param sourceIds | ||
* @param category | ||
*/ | ||
public async getExternalGamesForSourceIds( | ||
sourceIds: string[], | ||
category: EGameExternalGameCategory, | ||
) { | ||
const externalGames = await this.gameExternalGameRepository.find({ | ||
where: { | ||
uid: In(sourceIds), | ||
category, | ||
}, | ||
cache: { | ||
id: `external-games-ids-${category}-${sourceIds}`, | ||
milliseconds: days(1), | ||
}, | ||
}); | ||
|
||
return this.reOrderBySourceIds(sourceIds, externalGames); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { GameExternalGame } from "../../game/game-repository/entities/game-external-game.entity"; | ||
import { PaginationInfo } from "../../utils/pagination/pagination-response.dto"; | ||
import { ImporterResponseItemDto } from "./importer-response-item.dto"; | ||
|
||
export class ImporterPaginatedResponseDto { | ||
data: GameExternalGame[]; | ||
data: ImporterResponseItemDto[]; | ||
pagination: PaginationInfo; | ||
} |
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 @@ | ||
import { GameExternalGame } from "../../game/game-repository/entities/game-external-game.entity"; | ||
|
||
export class ImporterResponseItemDto extends GameExternalGame { | ||
/** | ||
* The preferred platform to use when adding this importer item to a user's collection. | ||
* @see CollectionsEntriesService#createOrUpdate | ||
*/ | ||
preferredPlatformId: number; | ||
} |
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