Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

userUpdateRequest.ts 634B

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