Skip to content

Commit

Permalink
feat(members): use isPresenceDuringAbo to check ongoing subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
mtthp committed Apr 26, 2024
1 parent 07c7f83 commit 702e9a4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/models/member.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pMap from 'p-map'
import {maxBy, sumBy, sortBy, chain, pick} from 'lodash-es'
import {customAlphabet} from 'nanoid'
import {add, differenceInMinutes, isSameDay, sub} from 'date-fns'
import {differenceInMinutes, isSameDay, sub} from 'date-fns'

import mongo from '../util/mongo.js'
import {buildPictureUrl, getUser as getWpUser} from '../util/wordpress.js'

import {computeSubcriptionEndDate, computeBalance} from '../calc.js'
import {computeSubcriptionEndDate, computeBalance, isPresenceDuringAbo} from '../calc.js'
import renderPlusDeTickets from '../emails/plus-de-tickets.js'

import * as Device from './device.js'
Expand Down Expand Up @@ -327,11 +327,7 @@ async function notifyUserBalanceDepletionOnArrival(user, referenceDate) {
const isBalanceDepleted = user.profile.balance <= 0
if (isArriving && isBalanceDepleted) {
// Check if there is a ongoing subscription
const nextDay = add(referenceDate, {days: 1}).toISOString().slice(0, 10)
const oneMonthBeforeNextDay = sub(new Date(nextDay), {months: 1}).toISOString().slice(0, 10)
const isSubscriptionOngoing = user.profile.abos.some(
abo => oneMonthBeforeNextDay < abo.aboStart && abo.aboStart <= nextDay
)
const isSubscriptionOngoing = isPresenceDuringAbo(referenceDate, user.profile.abos)

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

0 comments on commit 702e9a4

Please sign in to comment.