editable property added to deck short dto

This commit is contained in:
magdo
2025-10-26 21:27:00 +01:00
parent b75d27c7c8
commit fe8d5a53a5
4 changed files with 17 additions and 5 deletions
@@ -18,6 +18,7 @@ export interface ShortDeckDto {
cardCount: number;
creator: string;
creationdate: Date;
editable?: boolean;
}
export interface DetailDeckDto {
@@ -1,9 +1,10 @@
import { DeckAggregate } from '../../../Domain/Deck/DeckAggregate';
import { UserAggregate } from '../../../Domain/User/UserAggregate';
import { CreateDeckDto, UpdateDeckDto, ShortDeckDto, DetailDeckDto } from '../DeckDto';
import e from 'express';
export class DeckMapper {
static toShortDto(deck: DeckAggregate): ShortDeckDto {
static toShortDto(deck: DeckAggregate, userId?: string): ShortDeckDto {
return {
id: deck.id,
name: deck.name,
@@ -12,7 +13,8 @@ export class DeckMapper {
ctype: deck.ctype,
cardCount: deck.cards.length,
creator: deck.user?.username || 'Unknown',
creationdate: deck.creationdate
creationdate: deck.creationdate,
editable: deck.isEditable() ? deck.isEditable()(userId!) : undefined
};
}
@@ -29,7 +31,7 @@ export class DeckMapper {
};
}
static toShortDtoList(decks: DeckAggregate[]): ShortDeckDto[] {
static toShortDtoList(decks: DeckAggregate[], userId?: string): ShortDeckDto[] {
return decks.map(deck => ({
id: deck.id,
name: deck.name,
@@ -38,7 +40,8 @@ export class DeckMapper {
ctype: deck.ctype,
cardCount: deck.cards.length,
creator: deck.user?.username || 'Unknown',
creationdate: deck.creationdate
creationdate: deck.creationdate,
editable: deck.isEditable() ? deck.isEditable()(userId!) : undefined
}));
}
}