Skip to content

Commit

Permalink
fix: modified list to include filter
Browse files Browse the repository at this point in the history
  • Loading branch information
akp111 committed Jun 14, 2024
1 parent f5778ba commit ede9b65
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/restapi/src/lib/channels/getChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CONSTANTS from '../constantsV2';
import { getAPIBaseUrls, getCAIPAddress } from '../helpers';
import { axiosGet } from '../utils/axiosUtil';
import { parseSettings } from '../utils/parseSettings';

import { SOURCE_TYPES } from '../payloads/constants';
/**
* GET /v1/channels/{addressinCAIP}
*/
Expand All @@ -16,20 +16,22 @@ type getChannelsOptionsType = {
limit?: number;
sort?: string;
order?: string;
}
filter?: keyof typeof SOURCE_TYPES | 'ALL';
};

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 = 'ALL',
} = 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}`;
const requestUrl = `${apiEndpoint}?page=${page}&limit=${limit}&sort=${sort}&order=${order}&filter=${filter}`;

return await axiosGet(requestUrl)
.then((response) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ADDITIONAL_META_TYPE } from '../../lib/payloads/constants';
import { GetAliasInfoOptionsType } from '../alias';
import { NotifictaionType, ProgressHookType } from '../types';
import { SOURCE_TYPES } from '../payloads/constants';

export type SubscriptionOptions = {
account?: string;
Expand Down Expand Up @@ -151,6 +152,7 @@ export type ChannelListOptions = {
limit?: number;
sort?: ChannelListSortType;
order?: ChannelListOrderType;
filter?: keyof typeof SOURCE_TYPES | 'ALL';
};


Expand Down
2 changes: 2 additions & 0 deletions packages/restapi/src/lib/pushNotification/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export class Channel extends PushNotificationBaseClass {
limit,
sort = ChannelListSortType.SUBSCRIBER,
order = ChannelListOrderType.DESCENDING,
filter = 'ALL',
} = options || {};

return await PUSH_CHANNEL.getChannels({
Expand All @@ -452,6 +453,7 @@ export class Channel extends PushNotificationBaseClass {
limit,
sort,
order,
filter
});
} catch (error) {
throw new Error(`Push SDK Error: Contract : channel::list : ${error}`);
Expand Down
12 changes: 12 additions & 0 deletions packages/restapi/tests/lib/notification/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,16 @@ describe('PushAPI.channel functionality', () => {
expect(res).not.null;
});
});

describe('list', async () => {
it('Should the channel details', async () => {
const res = await userAlice.channel.list({});
expect(res).not.null;
});

it('Should fetch channel details based on the filter', async () => {
const res = await userAlice.channel.list({ filter: 'POLYGON_TEST_AMOY' });
expect(res).not.null;
});
});
});

0 comments on commit ede9b65

Please sign in to comment.