From 583e7098450fc97fdb9dc45663aac38efa4f9f15 Mon Sep 17 00:00:00 2001 From: Ashis Date: Tue, 24 Sep 2024 17:52:21 +0530 Subject: [PATCH 1/2] fix: added atg parameter for filter in list --- .../restapi/src/lib/channels/getChannels.ts | 19 +++++++++++-------- .../pushNotification/PushNotificationTypes.ts | 1 + .../src/lib/pushNotification/channel.ts | 4 +++- .../tests/lib/channel/getChannels.test.ts | 8 ++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/restapi/src/lib/channels/getChannels.ts b/packages/restapi/src/lib/channels/getChannels.ts index 4fb8528e9..5fe63d54d 100644 --- a/packages/restapi/src/lib/channels/getChannels.ts +++ b/packages/restapi/src/lib/channels/getChannels.ts @@ -15,22 +15,25 @@ type getChannelsOptionsType = { sort?: string; order?: string; filter?: number; -} + tag?: string; +}; export const getChannels = async (options: getChannelsOptionsType) => { - const { - env = CONSTANTS.ENV.PROD, - page = 1, - limit = 10, + const { + env = CONSTANTS.ENV.PROD, + page = 1, + limit = 10, sort = CONSTANTS.FILTER.CHANNEL_LIST.SORT.SUBSCRIBER, order = CONSTANTS.FILTER.CHANNEL_LIST.ORDER.DESCENDING, - filter + filter, + tag, } = options || {}; const API_BASE_URL = getAPIBaseUrls(env); const apiEndpoint = `${API_BASE_URL}/v1/channels`; - const requestUrl = `${apiEndpoint}?page=${page}&limit=${limit}&sort=${sort}&order=${order}${filter? '&filter=' + filter : ''}`; - + const requestUrl = `${apiEndpoint}?page=${page}&limit=${limit}&sort=${sort}&order=${order}${ + filter ? '&filter=' + filter : '' + }${tag ? '&tag=' + tag : ''}`; return await axiosGet(requestUrl) .then((response) => { return response.data; diff --git a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts index e8a6f5861..a061adfae 100644 --- a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts +++ b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts @@ -156,6 +156,7 @@ export type ChannelListOptions = { sort?: ChannelListSortType; order?: ChannelListOrderType; filter?: number; + tag?: string; }; export type TagListOptions = { diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index 0039a522c..349d5a686 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -477,6 +477,7 @@ export class Channel extends PushNotificationBaseClass { sort = ChannelListSortType.SUBSCRIBER, order = ChannelListOrderType.DESCENDING, filter, + tag, } = options || {}; return await PUSH_CHANNEL.getChannels({ @@ -485,7 +486,8 @@ export class Channel extends PushNotificationBaseClass { limit, sort, order, - filter + filter, + tag }); } catch (error) { throw new Error(`Push SDK Error: Contract : channel::list : ${error}`); diff --git a/packages/restapi/tests/lib/channel/getChannels.test.ts b/packages/restapi/tests/lib/channel/getChannels.test.ts index 1c97780d8..d3a0c3572 100644 --- a/packages/restapi/tests/lib/channel/getChannels.test.ts +++ b/packages/restapi/tests/lib/channel/getChannels.test.ts @@ -10,4 +10,12 @@ describe('PUSH_CHANNELS.getChannels', () => { }); console.log(res); }); + + it.only('Should fetch channels based on the filter and tags', async () => { + const res = await getChannels({ + env: ENV.DEV, + tag: 'Infrastructure' + }); + console.log(res.channels[0]); + }); }); From 27a6eee021aeacf6bbe13a6bcc1edbe4c51393fa Mon Sep 17 00:00:00 2001 From: Ashis Date: Tue, 24 Sep 2024 18:55:22 +0530 Subject: [PATCH 2/2] fix: added tag for search --- packages/restapi/src/lib/channels/search.ts | 3 +++ .../lib/pushNotification/PushNotificationTypes.ts | 1 + packages/restapi/src/lib/pushNotification/channel.ts | 2 ++ packages/restapi/tests/lib/channel/search.test.ts | 12 +++++++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/restapi/src/lib/channels/search.ts b/packages/restapi/src/lib/channels/search.ts index bef8f4037..77b9d433e 100644 --- a/packages/restapi/src/lib/channels/search.ts +++ b/packages/restapi/src/lib/channels/search.ts @@ -14,6 +14,7 @@ export type SearchChannelOptionsType = { page?: number; limit?: number; filter?: number; + tag?: string; // temp fix to support both new and old format oldFormat?: boolean; }; @@ -25,6 +26,7 @@ export const search = async (options: SearchChannelOptionsType) => { page = Constants.PAGINATION.INITIAL_PAGE, limit = Constants.PAGINATION.LIMIT, filter, + tag, oldFormat = true, } = options || {}; @@ -35,6 +37,7 @@ export const search = async (options: SearchChannelOptionsType) => { page, limit: getLimit(limit), query, + ...(tag && { tag }), ...(filter && { filter }), }; const requestUrl = `${apiEndpoint}?${getQueryParams(queryObj)}`; diff --git a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts index a061adfae..79407f65e 100644 --- a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts +++ b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts @@ -56,6 +56,7 @@ export type ChannelSearchOptions = { filter?: number; // temp fix to support both new and old format oldFormat?: boolean; + tag?: string; }; // Types related to notification diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index 349d5a686..0b93273bf 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -78,6 +78,7 @@ export class Channel extends PushNotificationBaseClass { page = Constants.PAGINATION.INITIAL_PAGE, limit = Constants.PAGINATION.LIMIT, filter, + tag, oldFormat = true } = options || {}; return await PUSH_CHANNEL.search({ @@ -85,6 +86,7 @@ export class Channel extends PushNotificationBaseClass { page: page, limit: limit, filter: filter, + tag: tag, env: this.env, oldFormat }); diff --git a/packages/restapi/tests/lib/channel/search.test.ts b/packages/restapi/tests/lib/channel/search.test.ts index d82c002ad..59df81a5e 100644 --- a/packages/restapi/tests/lib/channel/search.test.ts +++ b/packages/restapi/tests/lib/channel/search.test.ts @@ -12,7 +12,7 @@ describe('PUSH_CHANNELS.search', () => { console.log(res); }); - it.only('Should fetch channels based on the filter in new format', async () => { + it('Should fetch channels based on the filter in new format', async () => { const res = await search({ filter: 80002, env: ENV.DEV, @@ -21,4 +21,14 @@ describe('PUSH_CHANNELS.search', () => { }); console.log(res); }); + + it('Should fetch channels based on the filter in new format', async () => { + const res = await search({ + env: ENV.DEV, + query: "Channel", + oldFormat: false, + tag: "Infrastructure" + }); + console.log(res); + }); });