Skip to content

Commit

Permalink
Merge pull request #1395 from push-protocol/fix-updated-sdk-to-filter…
Browse files Browse the repository at this point in the history
…-via-tag

fix: added tag parameter for filter in list
  • Loading branch information
akp111 authored Sep 25, 2024
2 parents 665a96d + 27a6eee commit 21c08ba
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
19 changes: 11 additions & 8 deletions packages/restapi/src/lib/channels/getChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions packages/restapi/src/lib/channels/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -25,6 +26,7 @@ export const search = async (options: SearchChannelOptionsType) => {
page = Constants.PAGINATION.INITIAL_PAGE,
limit = Constants.PAGINATION.LIMIT,
filter,
tag,
oldFormat = true,
} = options || {};

Expand All @@ -35,6 +37,7 @@ export const search = async (options: SearchChannelOptionsType) => {
page,
limit: getLimit(limit),
query,
...(tag && { tag }),
...(filter && { filter }),
};
const requestUrl = `${apiEndpoint}?${getQueryParams(queryObj)}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -156,6 +157,7 @@ export type ChannelListOptions = {
sort?: ChannelListSortType;
order?: ChannelListOrderType;
filter?: number;
tag?: string;
};

export type TagListOptions = {
Expand Down
6 changes: 5 additions & 1 deletion packages/restapi/src/lib/pushNotification/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ export class Channel extends PushNotificationBaseClass {
page = Constants.PAGINATION.INITIAL_PAGE,
limit = Constants.PAGINATION.LIMIT,
filter,
tag,
oldFormat = true
} = options || {};
return await PUSH_CHANNEL.search({
query: query,
page: page,
limit: limit,
filter: filter,
tag: tag,
env: this.env,
oldFormat
});
Expand Down Expand Up @@ -477,6 +479,7 @@ export class Channel extends PushNotificationBaseClass {
sort = ChannelListSortType.SUBSCRIBER,
order = ChannelListOrderType.DESCENDING,
filter,
tag,
} = options || {};

return await PUSH_CHANNEL.getChannels({
Expand All @@ -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}`);
Expand Down
8 changes: 8 additions & 0 deletions packages/restapi/tests/lib/channel/getChannels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
});
12 changes: 11 additions & 1 deletion packages/restapi/tests/lib/channel/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
});
});

0 comments on commit 21c08ba

Please sign in to comment.