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; constructor() { this.repository = AppDataSource.getRepository(TurnHistoryAggregate); } async save(turnHistory: TurnHistoryAggregate): Promise { return await this.repository.save(turnHistory); } async findByGameId(gameId: string): Promise { return await this.repository.find({ where: { gameid: gameId }, order: { turnNumber: 'ASC', createdat: 'ASC' } }); } async findByGameAndPlayer(gameId: string, playerId: string): Promise { return await this.repository.find({ where: { gameid: gameId, playerid: playerId }, order: { turnNumber: 'ASC', createdat: 'ASC' } }); } async findLastNTurns(gameId: string, limit: number): Promise { return await this.repository.find({ where: { gameid: gameId }, order: { turnNumber: 'DESC', createdat: 'DESC' }, take: limit }); } async countTurnsByGame(gameId: string): Promise { return await this.repository.count({ where: { gameid: gameId } }); } async deleteByGameId(gameId: string): Promise { await this.repository.delete({ gameid: gameId }); } }