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/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 e8a6f5861..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 @@ -156,6 +157,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..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 }); @@ -477,6 +479,7 @@ export class Channel extends PushNotificationBaseClass { sort = ChannelListSortType.SUBSCRIBER, order = ChannelListOrderType.DESCENDING, filter, + tag, } = options || {}; return await PUSH_CHANNEL.getChannels({ @@ -485,7 +488,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]); + }); }); 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); + }); });