選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

userUpdateRequest.ts 667B

123456789101112131415161718192021222324252627282930
  1. import apiEndpoints from '../apiEndpoints';
  2. import { UserData } from '../../utils/interface/userInterface';
  3. interface UpdateResponse {
  4. message: string;
  5. }
  6. export const updateUser = async (
  7. userData: UserData,
  8. _id: string
  9. ): Promise<UpdateResponse> => {
  10. const response = await fetch(
  11. `http://localhost:3000${apiEndpoints.userUpdate}`,
  12. {
  13. method: 'PATCH',
  14. body: JSON.stringify({ userData, _id }),
  15. headers: {
  16. 'Content-Type': 'application/json',
  17. },
  18. }
  19. );
  20. const data: UpdateResponse = await response.json();
  21. if (!response.ok) {
  22. throw new Error(data.message || 'Something went wrong!');
  23. }
  24. return data;
  25. };