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

NV-2374 - 🚀 Feature: Allow notification feed filtering by custom payload data #3831

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ describe('GET /widget/notifications/feed', function () {
expect(response.data.length).to.equal(2);
});

it('should filter only messages that match the custom payload', async function () {
await session.triggerEvent(template.triggers[0].identifier, subscriberId, { role: 'author' });
await session.triggerEvent(template.triggers[0].identifier, subscriberId);

await session.awaitRunningJobs(template._id);

const messages = await messageRepository.findBySubscriberChannel(
session.environment._id,
subscriberProfile?._id as string,
ChannelTypeEnum.IN_APP
);

const message = messages[0];
const messageId = message._id;

const feed = await getSubscriberFeed({ payload: ['author'] });

expect(feed.data.length).to.equal(1);
expect(feed.data[0]._id).to.equal(messageId);
expect(message.payload.role).to.equal('author');
});

it('should filter only unseen messages', async function () {
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/widgets/queries/store.query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class StoreQuery {
seen?: boolean;
read?: boolean;
payload?: Record<string, unknown>;
}
1 change: 1 addition & 0 deletions libs/dal/src/repositories/message/message.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export type MessageDBModel = ChangePropsValueType<
| '_subscriberId'
| '_feedId'
| '_actorId'
| 'payload'
> & {
createdAt?: Date;
};
13 changes: 12 additions & 1 deletion libs/dal/src/repositories/message/message.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export class MessageRepository extends BaseRepository<MessageDBModel, MessageEnt
environmentId: string,
subscriberId: string,
channel: ChannelTypeEnum,
query: { feedId?: string[]; seen?: boolean; read?: boolean } = {}
query: {
feedId?: string[];
seen?: boolean;
read?: boolean;
payload?: string[];
} = {}
): Promise<MessageQuery & EnforceEnvId> {
const requestQuery: MessageQuery & EnforceEnvId = {
_environmentId: environmentId,
Expand Down Expand Up @@ -62,6 +67,12 @@ export class MessageRepository extends BaseRepository<MessageDBModel, MessageEnt
requestQuery.read = { $in: [true, false] };
}

if (query.payload != null) {
requestQuery.payload = {
$elemMatch: { $in: query.payload },
};
}

return requestQuery;
}

Expand Down
Loading