Skip to content

Commit 50fe027

Browse files
feat: Add category filter in notification fetch api
1 parent c8f8019 commit 50fe027

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ const { unviewedCount } = await sirenInstance.fetchUnviewedNotificationsCount()
114114
This method retrieves list of notifications in a paginated manner.
115115
116116
```bash
117-
const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size: 15, start: '', end: '', isRead: false });
117+
const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size: 15, start: '', end: '', isRead: false, category: 'posts' });
118118
```
119119
120+
Below are the accepted optional filters
120121
<table>
121122
<thead>
122123
<tr>
123124
<th>Argument</th>
124125
<th>Description</th>
125126
<th>Type</th>
126-
<th>Mandatory</th>
127127
<th>Default</th>
128128
</tr>
129129
</thead>
@@ -132,37 +132,38 @@ const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size:
132132
<td>page</td>
133133
<td>Current page</td>
134134
<td>number</td>
135-
<td>false</td>
136135
<td>0</td>
137136
</tr>
138137
<tr>
139138
<td>size</td>
140139
<td>Number of items fetched </td>
141140
<td>number</td>
142-
<td>false</td>
143141
<td>10</td>
144142
</tr>
145143
<tr>
146144
<td>start</td>
147145
<td>Accepts an ISO date string to filter notifications created after the specified date. By default, only the first 20 notifications will be fetched <br />
148146
eg: 2024-02-19T06:37:33.792+00:00</td>
149147
<td>string</td>
150-
<td>false</td>
151148
<td>null</td>
152149
</tr>
153150
<tr>
154151
<td>end</td>
155152
<td>Accepts an ISO date string to filter notifications created before the specified date. By default, only the first 20 notifications will be fetched <br />
156153
eg: 2024-02-19T06:37:33.792+00:00</td>
157154
<td>string</td>
158-
<td>false</td>
159155
<td>null</td>
160156
</tr>
161157
<tr>
162158
<td>isRead</td>
163159
<td>Filter to fetch read or unread notifications. If not specified, it retrieves both read and unread notifications</td>
164160
<td>boolean</td>
165-
<td>false</td>
161+
<td>null</td>
162+
</tr>
163+
<tr>
164+
<td>category</td>
165+
<td>Filter to fetch notifications by category. If not specified, it retrieves all notifications</td>
166+
<td>string</td>
166167
<td>null</td>
167168
</tr>
168169
</tbody>
@@ -196,19 +197,19 @@ const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size:
196197
By specifying the parameter eventType as either `NOTIFICATIONS` or `UNVIEWED_COUNT`, this method triggers the real-time retrieval of notifications or the count of unviewed notifications. If `NOTIFICATIONS` is selected, further parameters (`params`) can be provided for additional customization or filtering
197198
198199
```bash
199-
sirenInstance.startRealTimeFetch({ eventType: NOTIFICATIONS, params:{ page: 0, size: 15, start: '', end: '', isRead: false }});
200+
sirenInstance.startRealTimeFetch({ eventType: NOTIFICATIONS, params:{ page: 0, size: 15, start: '', end: '', isRead: false, category: 'posts' }});
200201

201202
sirenInstance.startRealTimeFetch({ eventType: UNVIEWED_COUNT });
202203
```
203204
204-
Below are the accepted filters for notifications
205+
Below are the accepted optional filters for `NOTIFICATIONS` event type
206+
205207
<table>
206208
<thead>
207209
<tr>
208210
<th>Argument</th>
209211
<th>Description</th>
210212
<th>Type</th>
211-
<th>Mandatory</th>
212213
<th>Default</th>
213214
</tr>
214215
</thead>
@@ -217,35 +218,36 @@ Below are the accepted filters for notifications
217218
<td>page</td>
218219
<td>Represents the current page</td>
219220
<td>number</td>
220-
<td>false</td>
221221
<td>0</td>
222222
</tr>
223223
<tr>
224224
<td>size</td>
225225
<td>The number of items to be fetched in a single call</td>
226226
<td>number</td>
227-
<td>false</td>
228227
<td>10</td>
229228
</tr>
230229
<tr>
231230
<td>start</td>
232231
<td>Accepts an ISO date string to filter notifications created after the specified date. By default, only the first 20 notifications will be fetched </td>
233232
<td>string</td>
234-
<td>false</td>
235233
<td>null</td>
236234
</tr>
237235
<tr>
238236
<td>end</td>
239237
<td>Accepts an ISO date string to filter notifications created before the specified date. By default, only the first 20 notifications will be fetched</td>
240238
<td>string</td>
241-
<td>false</td>
242239
<td>null</td>
243240
</tr>
244241
<tr>
245242
<td>isRead</td>
246243
<td>Filter to fetch read or unread notifications. If not specified, it retrieves both read and unread notifications</td>
247244
<td>number</td>
248-
<td>false</td>
245+
<td>null</td>
246+
</tr>
247+
<tr>
248+
<td>category</td>
249+
<td>Filter to fetch notifications by category. If not specified, it retrieves all notifications</td>
250+
<td>string</td>
249251
<td>null</td>
250252
</tr>
251253
</tbody>

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ export type FetchNotificationsParamsType = {
128128
* Option for sorting notifications
129129
*/
130130
sort?: "createdAt" | "updatedAt";
131+
132+
/**
133+
* Option for filtering based on category
134+
*/
135+
category?: string;
131136
};
132137

133138
/**

0 commit comments

Comments
 (0)