Skip to content

Commit 32913fa

Browse files
author
meow12
authored
feat(sse): add users to channels (#80)
allow add users to groups and channels after creation
1 parent 2cf3cf8 commit 32913fa

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/components/sse.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ export async function deleteGroup({secretKey, id}) {
4646
return response;
4747
}
4848

49+
export async function addUsersToGroup({secretKey, id, users}) {
50+
const response = await server.loadJson(
51+
`${
52+
Config.eventsApiUrl
53+
}${Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.ADD_USERS_TO_GROUP(id)}`,
54+
{
55+
method: 'POST',
56+
headers: {
57+
'X-CM-ProjectId': Config.projectId,
58+
Authorization: `Bearer ${secretKey || Config.secretKey}`,
59+
Accept: 'application/json',
60+
'Content-Type': 'application/json',
61+
},
62+
body: JSON.stringify({
63+
users,
64+
}),
65+
}
66+
);
67+
68+
return response;
69+
}
70+
4971
export async function getGroups({
5072
secretKey,
5173
pageNumber,
@@ -163,6 +185,31 @@ export async function deleteChannel({secretKey, groupId, id}) {
163185
return response;
164186
}
165187

188+
export async function addUsersToChannel({secretKey, groupId, id, users}) {
189+
const response = await server.loadJson(
190+
`${
191+
Config.eventsApiUrl
192+
}${Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.ADD_USERS_TO_CHANNEL(
193+
groupId,
194+
id
195+
)}`,
196+
{
197+
method: 'POST',
198+
headers: {
199+
'X-CM-ProjectId': Config.projectId,
200+
Authorization: `Bearer ${secretKey || Config.secretKey}`,
201+
Accept: 'application/json',
202+
'Content-Type': 'application/json',
203+
},
204+
body: JSON.stringify({
205+
users,
206+
}),
207+
}
208+
);
209+
210+
return response;
211+
}
212+
166213
export async function getChannels({
167214
secretKey,
168215
groupId,

src/routes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ export const CONFIG = {
7676
SERVER_EVENTS: {
7777
CREATE_GROUP: '/v2/notifications/server-events/groups',
7878
DELETE_GROUP: (id) => `/v2/notifications/server-events/groups/${id}`,
79+
ADD_USERS_TO_GROUP: (id) =>
80+
`/v2/notifications/server-events/groups/${id}/users`,
7981
GET_GROUPS: '/v2/notifications/server-events/groups',
8082
GET_GROUP: (id) => `/v2/notifications/server-events/groups/${id}`,
8183
CREATE_CHANNEL: (groupId) =>
8284
`/v2/notifications/server-events/groups/${groupId}/channels`,
8385
DELETE_CHANNEL: (groupId, id) =>
8486
`/v2/notifications/server-events/groups/${groupId}/channels/${id}`,
87+
ADD_USERS_TO_CHANNEL: (groupId, id) =>
88+
`/v2/notifications/server-events/groups/${groupId}/channels/${id}/users`,
8589
GET_CHANNELS: (groupId) =>
8690
`/v2/notifications/server-events/groups/${groupId}/channels`,
8791
GET_MESSAGES: '/v2/notifications/server-events/messages',

0 commit comments

Comments
 (0)