Skip to content

Commit

Permalink
feat(lottery): notify winner if they win via ticket numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Sep 19, 2023
1 parent 44c039c commit 01bdf63
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions server/src/modules/lottery/buyinlottery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ export class BuyInLotteryService implements OnModuleInit {
const newRecord = new LotteryBuyInDraw(this.generateBuyTicketNumber());
emCtx.persist(newRecord);
await emCtx.flush();

const winningTicket = await this.buyinTickets.findOne({
ticketNumber: newRecord.ticketNumber,
createdAt: { $gte: startOfToday() },
});
if (!winningTicket) return;

this.events.emit('notification.create', {
userId: winningTicket.userId,
notification: {
liveAt: new Date(),
text: `You have won the ticket lottery with ticket ${winningTicket.ticketNumber}!`,
actions: [
{
text: 'Claim',
action: 'navigate',
actionData: { url: '/' },
},
],
},
expiresAfterHours: 1,
});
}

public async buyTicket(userId: string): Promise<UserResponse> {
Expand Down Expand Up @@ -175,13 +197,7 @@ export class BuyInLotteryService implements OnModuleInit {
text: `You have won the ticket lottery with ticket ${
todayTicket.ticketNumber
} and got ${total.toLocaleString()} coins!`,
actions: [
{
text: 'Claim',
action: 'navigate',
actionData: { url: '/' },
},
],
actions: [],
},
expiresAfterHours: 1,
});
Expand Down

0 comments on commit 01bdf63

Please sign in to comment.