@@ -2,6 +2,8 @@ import { handleResponse, authHeader } from "../_helpers/service.helpers";
22import { User } from "../types/user" ;
33import { API_URL } from "../_config/api.config" ;
44
5+ const ENDPOINT_URL = "/users"
6+
57export const usersService = {
68 login,
79 logout,
@@ -17,7 +19,7 @@ function login(email: string, password: string): Promise<User> {
1719 body : JSON . stringify ( { email, password } ) ,
1820 } ;
1921
20- return fetch ( `${ API_URL } /users /login` , requestOptions )
22+ return fetch ( `${ API_URL } ${ ENDPOINT_URL } /login` , requestOptions )
2123 . then ( handleResponse )
2224 . then ( ( user ) => {
2325 setUserInLocalStorage ( user )
@@ -32,7 +34,7 @@ function register(firstName: string, lastName: string, email: string, password:
3234 body : JSON . stringify ( { firstName, lastName, email, password } ) ,
3335 } ;
3436
35- return fetch ( `${ API_URL } /users /register` , requestOptions )
37+ return fetch ( `${ API_URL } ${ ENDPOINT_URL } /register` , requestOptions )
3638 . then ( handleResponse )
3739 . then ( ( user ) => {
3840 setUserInLocalStorage ( user )
@@ -47,7 +49,7 @@ function update({ id, firstName, lastName, email }: { id: string, firstName: str
4749 body : JSON . stringify ( { firstName, lastName, email } ) ,
4850 } ;
4951
50- return fetch ( `${ API_URL } /users /${ id } ` , requestOptions )
52+ return fetch ( `${ API_URL } ${ ENDPOINT_URL } /${ id } ` , requestOptions )
5153 . then ( handleResponse )
5254 . then ( ( user ) => {
5355 setUserInLocalStorage ( user )
@@ -62,7 +64,7 @@ function changePassword(password: string): Promise<boolean> {
6264 body : JSON . stringify ( { password } ) ,
6365 } ;
6466
65- return fetch ( `${ API_URL } /users /password` , requestOptions )
67+ return fetch ( `${ API_URL } ${ ENDPOINT_URL } /password` , requestOptions )
6668 . then ( handleResponse )
6769}
6870
0 commit comments