Skip to content

Commit

Permalink
fix(members): parse heartbeat as Date on arrival notification
Browse files Browse the repository at this point in the history
  • Loading branch information
mtthp committed Apr 27, 2024
1 parent 5e955c1 commit 520f511
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/models/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export async function heartbeatMembers(memberIds, referenceDate) {
{$set: {'profile.heartbeat': referenceDate.toISOString()}}
)

notifyUserBalanceDepletionOnArrival(updatedUser.value, referenceDate.toISOString().slice(0, 10))
notifyUserBalanceDepletionOnArrival(updatedUser.value, referenceDate)
}))
}

Expand Down Expand Up @@ -322,12 +322,14 @@ export async function computeMemberFromUser(user, options = {}) {
* and has no more tickets
* and has no ongoing subscription
*/
async function notifyUserBalanceDepletionOnArrival(user, referenceDate) {
const isArriving = !isSameDay(new Date(user.profile.heartbeat), referenceDate)
async function notifyUserBalanceDepletionOnArrival(user, newHeartbeat) {
const previousHeartbeat = new Date(user.profile.heartbeat)
const isArriving = !isSameDay(previousHeartbeat, newHeartbeat)
const isBalanceDepleted = user.profile.balance <= 0
if (isArriving && isBalanceDepleted) {
// Check if there is a ongoing subscription
const isSubscriptionOngoing = isPresenceDuringAbo(referenceDate, user.profile.abos)
const newHeartbeatDate = newHeartbeat.toISOString().slice(0, 10)
const isSubscriptionOngoing = isPresenceDuringAbo(newHeartbeatDate, user.profile.abos)

if (!isSubscriptionOngoing) {
// Send a notification email
Expand Down

0 comments on commit 520f511

Please sign in to comment.