final POC
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { Repository } from 'typeorm';
|
||||
import { AppDataSource } from '../ormconfig';
|
||||
import { ITurnHistoryRepository } from '../../Domain/IRepository/ITurnHistoryRepository';
|
||||
import { TurnHistoryAggregate } from '../../Domain/Game/TurnHistoryAggregate';
|
||||
|
||||
export class TurnHistoryRepository implements ITurnHistoryRepository {
|
||||
private repository: Repository<TurnHistoryAggregate>;
|
||||
|
||||
constructor() {
|
||||
this.repository = AppDataSource.getRepository(TurnHistoryAggregate);
|
||||
}
|
||||
|
||||
async save(turnHistory: TurnHistoryAggregate): Promise<TurnHistoryAggregate> {
|
||||
return await this.repository.save(turnHistory);
|
||||
}
|
||||
|
||||
async findByGameId(gameId: string): Promise<TurnHistoryAggregate[]> {
|
||||
return await this.repository.find({
|
||||
where: { gameid: gameId },
|
||||
order: { turnNumber: 'ASC', createdat: 'ASC' }
|
||||
});
|
||||
}
|
||||
|
||||
async findByGameAndPlayer(gameId: string, playerId: string): Promise<TurnHistoryAggregate[]> {
|
||||
return await this.repository.find({
|
||||
where: {
|
||||
gameid: gameId,
|
||||
playerid: playerId
|
||||
},
|
||||
order: { turnNumber: 'ASC', createdat: 'ASC' }
|
||||
});
|
||||
}
|
||||
|
||||
async findLastNTurns(gameId: string, limit: number): Promise<TurnHistoryAggregate[]> {
|
||||
return await this.repository.find({
|
||||
where: { gameid: gameId },
|
||||
order: { turnNumber: 'DESC', createdat: 'DESC' },
|
||||
take: limit
|
||||
});
|
||||
}
|
||||
|
||||
async countTurnsByGame(gameId: string): Promise<number> {
|
||||
return await this.repository.count({
|
||||
where: { gameid: gameId }
|
||||
});
|
||||
}
|
||||
|
||||
async deleteByGameId(gameId: string): Promise<void> {
|
||||
await this.repository.delete({ gameid: gameId });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user