game workflow corrected

This commit is contained in:
magdo
2025-10-30 19:39:41 +01:00
parent 79786d8bb1
commit 9f3a5b6fd7
3 changed files with 16 additions and 6 deletions
@@ -13,7 +13,7 @@ export class DeckMapper {
cardCount: deck.cards.length, cardCount: deck.cards.length,
creator: deck.user?.username || 'Unknown', creator: deck.user?.username || 'Unknown',
creationdate: deck.creationdate, creationdate: deck.creationdate,
editable: deck.isEditable() ? deck.isEditable()(userId!) : undefined editable: deck.isEditable(userId!) ? deck.isEditable(userId!) : undefined
}; };
} }
@@ -40,7 +40,7 @@ export class DeckMapper {
cardCount: deck.cards.length, cardCount: deck.cards.length,
creator: deck.user?.username || 'Unknown', creator: deck.user?.username || 'Unknown',
creationdate: deck.creationdate, creationdate: deck.creationdate,
editable: deck.isEditable() ? deck.isEditable()(userId!) : undefined editable: deck.isEditable(userId!) ? deck.isEditable(userId!) : undefined
})); }));
} }
} }
@@ -88,10 +88,16 @@ export class DeckAggregate {
@JoinColumn({ name: 'user_id' }) @JoinColumn({ name: 'user_id' })
user!: UserAggregate | null; user!: UserAggregate | null;
isEditable() { isEditable(userId:string): boolean{
// A deck is editable if the user is the creator // A deck is editable if the user is the creator
return (userId: string) => { if (!this.user) {
return this.user?.id.toString() === userId; logError(`DeckAggregate.isEditable: User is null for deck id ${this.id}`);
}; return false;
}
//if admin, always editable
if (this.user?.isAdmin) {
return true;
}
return this.user?.id.toString() === userId;;
} }
} }
@@ -55,4 +55,8 @@ export class UserAggregate {
@Column({ type: 'timestamp', nullable: true }) @Column({ type: 'timestamp', nullable: true })
Orglogindate!: Date | null; Orglogindate!: Date | null;
get isAdmin(): boolean {
return this.state === UserState.ADMIN;
}
} }