fel kesz game backend

This commit is contained in:
2025-09-15 19:00:35 +02:00
parent 7963f28021
commit 3af8de2797
267 changed files with 15655 additions and 347 deletions
@@ -1,5 +1,8 @@
import { n } from "framer-motion/dist/types.d-D0HXPxHm";
export interface UpdateDeckCommand {
id: string;
userstate?: number;
name?: string;
type?: number;
userid?: string;
@@ -2,13 +2,49 @@ import { IDeckRepository } from '../../../Domain/IRepository/IDeckRepository';
import { UpdateDeckCommand } from './UpdateDeckCommand';
import { ShortDeckDto } from '../../DTOs/DeckDto';
import { DeckMapper } from '../../DTOs/Mappers/DeckMapper';
import { DeckAggregate } from '../../../Domain/Deck/DeckAggregate';
import { logError } from '../../Services/Logger';
export class UpdateDeckCommandHandler {
constructor(private readonly deckRepo: IDeckRepository) {}
async execute(cmd: UpdateDeckCommand): Promise<ShortDeckDto | null> {
const updated = await this.deckRepo.update(cmd.id, { ...cmd });
if (!updated) return null;
return DeckMapper.toShortDto(updated);
if(cmd.state !== undefined && cmd.userstate!==1) {
throw new Error('Only admin users can change deck state');
}
try {
let existingDeck: DeckAggregate | null = null;
if (cmd.userstate === 1) {
existingDeck = await this.deckRepo.findByIdIncludingDeleted(cmd.id);
} else {
existingDeck = await this.deckRepo.findById(cmd.id);
}
if (!existingDeck) {
logError(`Deck not found with ID: ${cmd.id}`);
throw new Error('Deck not found');
}
const for_update: Partial<DeckAggregate> = {};
if(cmd.name !== undefined) for_update.name = cmd.name;
if(cmd.type !== undefined) for_update.type = cmd.type;
if(cmd.cards !== undefined) for_update.cards = cmd.cards;
if(cmd.ctype !== undefined) for_update.ctype = cmd.ctype;
if(cmd.state !== undefined) for_update.state = cmd.state;
// Ensure we have something to update
if (Object.keys(for_update).length === 0) {
throw new Error('No fields provided for update');
}
const deck = await this.deckRepo.update(cmd.id, { ...for_update });
if(!deck) {
logError(`Deck update failed for ID: ${cmd.id}. Update returned null.`);
throw new Error('Failed to update deck');
}
return DeckMapper.toShortDto(deck);
} catch (error: any) {
logError(`Error updating deck: ${cmd.id}`, error);
throw error;
}
}
}
@@ -1,14 +1,14 @@
import { IDeckRepository } from '../../../Domain/IRepository/IDeckRepository';
import { GetDeckByIdQuery } from './GetDeckByIdQuery';
import { ShortDeckDto } from '../../DTOs/DeckDto';
import { DetailDeckDto } from '../../DTOs/DeckDto';
import { DeckMapper } from '../../DTOs/Mappers/DeckMapper';
export class GetDeckByIdQueryHandler {
constructor(private readonly deckRepo: IDeckRepository) {}
async execute(query: GetDeckByIdQuery): Promise<ShortDeckDto | null> {
async execute(query: GetDeckByIdQuery): Promise<DetailDeckDto | null> {
const deck = await this.deckRepo.findById(query.id);
if (!deck) return null;
return DeckMapper.toShortDto(deck);
return DeckMapper.toDetailDto(deck);
}
}