-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.t
More file actions
42 lines (34 loc) · 1.43 KB
/
notes.t
File metadata and controls
42 lines (34 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# async getRandomPrize(): Promise<Prize> {
# const prizes = await this.prizesRepository.find({ where: { quantity: MoreThan(0) } });
# if (prizes.length === 0) {
# throw new NotFoundException('No available prizes');
# }
# const randomIndex = Math.floor(Math.random() * prizes.length);
# return prizes[randomIndex];
# }
# async claimPrize(playerId: number): Promise<PlayerPrize> {
# const player = await this.playersRepository.findOne({ where: { id: playerId }, relations: ['prizes'] });
# if (!player) {
# throw new NotFoundException(`Player with ID ${playerId} not found`);
# }
# const prize = await this.getRandomPrize();
# prize.quantity -= 1;
# const playerPrize = this.playerPrizesRepository.create({
# player,
# prize,
# isClaimed: true,
# });
# await this.prizesRepository.save(prize);
# return this.playerPrizesRepository.save(playerPrize);
# }
# async assignUnclaimedPrizes(): Promise<void> {
# const unclaimedPrizes = await this.playerPrizesRepository.find({ where: { isClaimed: false } });
# for (const playerPrize of unclaimedPrizes) {
# playerPrize.isClaimed = true;
# await this.playerPrizesRepository.save(playerPrize);
# }
# }
# async createPrize(createPrizeDto: CreatePrizeDto): Promise<Prize> {
# const prize = this.prizesRepository.create(createPrizeDto);
# return this.prizesRepository.save(prize);
# }