Skip to content

Commit

Permalink
fix: added atg parameter for filter in list
Browse files Browse the repository at this point in the history
  • Loading branch information
akp111 committed Sep 24, 2024
1 parent 665a96d commit 583e709
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export type ChannelListOptions = {
sort?: ChannelListSortType;
order?: ChannelListOrderType;
filter?: number;
tag?: string;
};

export type TagListOptions = {
Expand Down
4 changes: 3 additions & 1 deletion packages/restapi/src/lib/pushNotification/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ export class Channel extends PushNotificationBaseClass {
sort = ChannelListSortType.SUBSCRIBER,
order = ChannelListOrderType.DESCENDING,
filter,
tag,
} = options || {};

return await PUSH_CHANNEL.getChannels({
Expand All @@ -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}`);
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]);
});
});

0 comments on commit 583e709

Please sign in to comment.