You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

accountRequests.ts 901B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import apiEndpoints from '../apiEndpoints';
  2. interface CreateUserResponse {
  3. message: string;
  4. }
  5. export const createUser = async (
  6. fullName: string,
  7. username: string,
  8. email: string,
  9. password: string,
  10. address: string,
  11. address2: string,
  12. city: string,
  13. country: string,
  14. postcode: string
  15. ): Promise<CreateUserResponse> => {
  16. const response = await fetch(
  17. `http://localhost:3000${apiEndpoints.account.createUser}`,
  18. {
  19. method: 'POST',
  20. body: JSON.stringify({
  21. fullName,
  22. username,
  23. email,
  24. password,
  25. address,
  26. address2,
  27. city,
  28. country,
  29. postcode,
  30. }),
  31. headers: {
  32. 'Content-Type': 'application/json',
  33. },
  34. }
  35. );
  36. const data: CreateUserResponse = await response.json();
  37. if (!response.ok) {
  38. throw new Error(data.message || 'Something went wrong!');
  39. }
  40. return data;
  41. };