Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added tag parameter for filter in list #1395

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading