From 4826d1c6ee5220d62f7600d23b92c85ba5d429cc Mon Sep 17 00:00:00 2001 From: Alp Date: Fri, 26 Jan 2024 18:04:54 +0300 Subject: [PATCH] Implement isInTournament function --- src/entities/user.entity.ts | 9 ++++++++- src/repositories/tournamentGroup.repository.ts | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/entities/user.entity.ts b/src/entities/user.entity.ts index b885284..f2b20e2 100644 --- a/src/entities/user.entity.ts +++ b/src/entities/user.entity.ts @@ -53,6 +53,13 @@ export class User { } public isInTournament() { - return true; //Todo: Implement later + const joinedTournamentAt = new Date(this.joinedTournamentAt); + const now = new Date(); + + return ( + joinedTournamentAt.getUTCFullYear() === now.getUTCFullYear() && + joinedTournamentAt.getUTCMonth() === now.getUTCMonth() && + joinedTournamentAt.getUTCDate() === now.getUTCDate() + ); } } diff --git a/src/repositories/tournamentGroup.repository.ts b/src/repositories/tournamentGroup.repository.ts index 8b7fb5b..3ab0da7 100644 --- a/src/repositories/tournamentGroup.repository.ts +++ b/src/repositories/tournamentGroup.repository.ts @@ -113,10 +113,11 @@ export class TournamentGroupRepository { username: { S: data.username }, }, UpdateExpression: - 'SET groupId = :newGroupId, claimedReward = :claimedRewardVal', + 'SET groupId = :newGroupId, claimedReward = :claimedRewardVal, joinedTournamentAt = :joinedTournamentAtVal', ExpressionAttributeValues: { ':newGroupId': { S: data.groupId }, ':claimedRewardVal': { BOOL: false }, + ':joinedTournamentAtVal': { S: new Date().toISOString()}, }, }, },