From 1d7bd85f10da27d79428088ee3d12967c9f6bd67 Mon Sep 17 00:00:00 2001 From: gitstart Date: Thu, 20 Jul 2023 14:41:33 +0000 Subject: [PATCH 1/2] feat: allow notification feed filtering by custom payload data Co-authored-by: AsiwajuDev <17790578+AsiwajuDev@users.noreply.github.com> Co-authored-by: Azerii <32432927+Azerii@users.noreply.github.com> --- .../widgets/e2e/get-notification-feed.e2e.ts | 20 +++++++++++++++++++ .../src/app/widgets/queries/store.query.ts | 1 + .../repositories/message/message.entity.ts | 1 + .../message/message.repository.ts | 13 +++++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts b/apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts index f2fd2715274..f1af62892d3 100644 --- a/apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts +++ b/apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts @@ -69,6 +69,26 @@ 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 messageId = messages[0]._id; + + const feed = await getSubscriberFeed({ payload: ['author'] }); + + expect(feed.data.length).to.equal(1); + expect(feed.data[0]._id).to.equal(messageId); + expect(feed.data[0].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); diff --git a/apps/api/src/app/widgets/queries/store.query.ts b/apps/api/src/app/widgets/queries/store.query.ts index 1fce0f6eff9..330a7448da5 100644 --- a/apps/api/src/app/widgets/queries/store.query.ts +++ b/apps/api/src/app/widgets/queries/store.query.ts @@ -1,4 +1,5 @@ export class StoreQuery { seen?: boolean; read?: boolean; + payload?: Record; } diff --git a/libs/dal/src/repositories/message/message.entity.ts b/libs/dal/src/repositories/message/message.entity.ts index d2470b55c17..437d4a77f64 100644 --- a/libs/dal/src/repositories/message/message.entity.ts +++ b/libs/dal/src/repositories/message/message.entity.ts @@ -101,6 +101,7 @@ export type MessageDBModel = ChangePropsValueType< | '_subscriberId' | '_feedId' | '_actorId' + | 'payload' > & { createdAt?: Date; }; diff --git a/libs/dal/src/repositories/message/message.repository.ts b/libs/dal/src/repositories/message/message.repository.ts index 2a8fc0e8f8f..dec25200bfb 100644 --- a/libs/dal/src/repositories/message/message.repository.ts +++ b/libs/dal/src/repositories/message/message.repository.ts @@ -23,7 +23,12 @@ export class MessageRepository extends BaseRepository { const requestQuery: MessageQuery & EnforceEnvId = { _environmentId: environmentId, @@ -62,6 +67,12 @@ export class MessageRepository extends BaseRepository Date: Thu, 20 Jul 2023 16:06:56 +0000 Subject: [PATCH 2/2] fix: update test Co-authored-by: AsiwajuDev <17790578+AsiwajuDev@users.noreply.github.com> Co-authored-by: Azerii <32432927+Azerii@users.noreply.github.com> --- apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts b/apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts index f1af62892d3..3a5778e3f5a 100644 --- a/apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts +++ b/apps/api/src/app/widgets/e2e/get-notification-feed.e2e.ts @@ -80,13 +80,15 @@ describe('GET /widget/notifications/feed', function () { subscriberProfile?._id as string, ChannelTypeEnum.IN_APP ); - const messageId = messages[0]._id; + + 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(feed.data[0].role).to.equal('author'); + expect(message.payload.role).to.equal('author'); }); it('should filter only unseen messages', async function () {