-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): run step filters - is online logic #2472
feat(api): run step filters - is online logic #2472
Conversation
NV-1434 Implement the functionality that will run online filters logic
Changes will need to be applied here |
const matcher = new MessageMatcher( | ||
{ findOne: () => Promise.resolve(getSubscriber()) } as any, | ||
undefined as any, | ||
undefined as any | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a better way how to pass a mocked SubscriberRepository
instance with Sinon to the MessageMatcher
, so decided to do that this way.
@@ -27,7 +27,7 @@ const subscriberSchema = new Schema( | |||
type: Schema.Types.Boolean, | |||
default: false, | |||
}, | |||
lastOnlineAt: Schema.Types.String, | |||
lastOnlineAt: Schema.Types.Date, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in DB we do store it as a date
const isOnlineMatch = subscriber?.isOnline === filter.value; | ||
if (filter.on === 'isOnline') { | ||
return isOnlineMatch; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the isOnline
filter we just do check if the isOnline
value on the subscriber matches with the filter value
const currentDate = new Date(); | ||
const lastOnlineAt = subscriber?.lastOnlineAt ? parseISO(subscriber?.lastOnlineAt) : new Date(); | ||
const diff = differenceIn(currentDate, lastOnlineAt, filter.timeOperator); | ||
|
||
return subscriber?.isOnline || (!subscriber?.isOnline && diff <= filter.value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the isOnlineInLast
we do check:
- if the subscriber is online
- or if the subscriber is offline but was online in the last X minutes, hours, days
…is-online-filters-logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
…is-online-filters-logic
…is-online-filters-logic
What change does this PR introduce?
Implemented the step filters logic for the "Is Online Filters".
Why was this change needed?
This is a part of the "Is Online Filters" functionality.
Other information (Screenshots)