-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccad72a
commit ab16af3
Showing
7 changed files
with
54 additions
and
14 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { PostUsersToGroupsResponse, PutUsersToGroupsRequest } from './types'; | ||
|
||
async function postUserToGroups({ | ||
groupId, | ||
userToGroupId, | ||
}: PutUsersToGroupsRequest): Promise<PostUsersToGroupsResponse | null> { | ||
try { | ||
const response = await fetch( | ||
`${import.meta.env.VITE_SERVER_URL}/api/users-to-groups/${userToGroupId}`, | ||
{ | ||
method: 'POST', | ||
credentials: 'include', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ groupId }), | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP Error! Status: ${response.status}`); | ||
} | ||
|
||
const group = (await response.json()) as { data: PostUsersToGroupsResponse }; | ||
return group.data; | ||
} catch (error) { | ||
console.error('Error during POST user to groups request:', error); | ||
if (error instanceof Error) { | ||
throw new Error(error.message); | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
export default postUserToGroups; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
export type PostUserToGroupsRequest = { | ||
groupId?: string; | ||
secret?: string; | ||
}; | ||
|
||
export type PostUserToGroupsResponse = { | ||
type UsersToGroups = { | ||
id: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
userId: string; | ||
groupCategoryId: string | null; | ||
groupId: string; | ||
}; | ||
|
||
export type PostUsersToGroupsRequest = { | ||
groupId?: string; | ||
secret?: string; | ||
}; | ||
|
||
export type PutUsersToGroupsRequest = { | ||
userToGroupId: string; | ||
groupId: string; | ||
}; | ||
|
||
export type PostUsersToGroupsResponse = UsersToGroups; | ||
export type PutUsersToGroupsResponse = UsersToGroups; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters