Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 129ea694f8 | |||
| 9f3a5b6fd7 |
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user