Skip to content
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

Conversation

LetItRock
Copy link
Contributor

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)

@LetItRock LetItRock self-assigned this Jan 11, 2023
@linear
Copy link

linear bot commented Jan 11, 2023

NV-1434 Implement the functionality that will run online filters logic

Changes will need to be applied here message-matcher.service.ts

Comment on lines +575 to +579
const matcher = new MessageMatcher(
{ findOne: () => Promise.resolve(getSubscriber()) } as any,
undefined as any,
undefined as any
);
Copy link
Contributor Author

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,
Copy link
Contributor Author

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

Comment on lines +145 to +148
const isOnlineMatch = subscriber?.isOnline === filter.value;
if (filter.on === 'isOnline') {
return isOnlineMatch;
}
Copy link
Contributor Author

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

Comment on lines +150 to +154
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);
Copy link
Contributor Author

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

Copy link
Contributor

@BiswaViraj BiswaViraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Base automatically changed from nv-1432-update-types-for-step-filter to nv-1441-is-online-filters-feature January 11, 2023 16:04
@LetItRock LetItRock merged commit 4dbfbe5 into nv-1441-is-online-filters-feature Jan 11, 2023
@LetItRock LetItRock deleted the nv-1434-run-is-online-filters-logic branch January 11, 2023 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants