Skip to content

Commit

Permalink
feat: segments API (wip #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaziine committed Dec 28, 2023
1 parent 5d212df commit 9a96e20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2891,15 +2891,17 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
/**
* querySegments - Query Segments
*
* @param {filter} filter MongoDB style filter conditions
* @param {QuerySegmentsOptions} options Options for sorting/paginating the results
*
* @return {Segment[]} Segments
*/
async querySegments(filters: SegmentFilters, options: QuerySegmentsOptions = {}) {
async querySegments(filter: {}, options: QuerySegmentsOptions = {}) {
return await this.get<{
segments: Segment[];
}>(this.baseURL + `/segments`, {
payload: {
filter_conditions: filters,
filter: filter,
...options,
},
});
Expand All @@ -2916,6 +2918,18 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
return this.delete<APIResponse>(this.baseURL + `/segments/${id}`);
}

/**
* segmentTargetExists - Check if a target exists in a segment
*
* @param {string} segmentId Segment ID
* @param {string} targetId Target ID
*
* @return {Promise<APIResponse>} The Server Response
*/
async segmentTargetExists(segmentId: string, targetId: string) {
return this.get<APIResponse>(this.baseURL + `/segments/${segmentId}/target/${targetId}`);
}

/**
* createCampaign - Creates a Campaign
*
Expand Down
5 changes: 2 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,7 @@ export type UpdateSegmentParams = {

export type SortParam = {
field: string;
direction?: 'asc' | 'desc';
direction?: AscDesc;
}

export type Pager = {
Expand All @@ -2420,8 +2420,7 @@ export type Pager = {

export type QuerySegmentsOptions = {
sort?: SortParam[];
pager?: Pager;
}
} & Pager;

export type CampaignSortField = {
field: string;
Expand Down

0 comments on commit 9a96e20

Please sign in to comment.