Merge pull request 'game workflow corrected' (#84) from Backend_Fix into main
Reviewed-on: #84
This commit was merged in pull request #84.
This commit is contained in:
@@ -13,7 +13,7 @@ export class DeckMapper {
|
||||
cardCount: deck.cards.length,
|
||||
creator: deck.user?.username || 'Unknown',
|
||||
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,
|
||||
creator: deck.user?.username || 'Unknown',
|
||||
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' })
|
||||
user!: UserAggregate | null;
|
||||
|
||||
isEditable() {
|
||||
isEditable(userId:string): boolean{
|
||||
// A deck is editable if the user is the creator
|
||||
return (userId: string) => {
|
||||
return this.user?.id.toString() === userId;
|
||||
};
|
||||
if (!this.user) {
|
||||
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 })
|
||||
Orglogindate!: Date | null;
|
||||
|
||||
get isAdmin(): boolean {
|
||||
return this.state === UserState.ADMIN;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user