-
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.
feat: ⚡ add fav route to add / remove fav
- Loading branch information
Showing
5 changed files
with
86 additions
and
31 deletions.
There are no files selected for viewing
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
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,49 +1,49 @@ | ||
import { User, UserWithoutId } from '@/interfaces/user' | ||
import { User, UserWithoutId } from "@/interfaces/user"; | ||
|
||
const BASE_URL = process.env.API_URL | ||
const BASE_URL = process.env.API_URL; | ||
|
||
//para actualizar solo los tags apenas se registra | ||
export async function patchUserService(id: string, userData: UserWithoutId) { | ||
const url = BASE_URL + '/user/' + id | ||
const url = BASE_URL + "/user/" + id; | ||
|
||
console.log(url) | ||
console.log(url); | ||
const response = await fetch(url, { | ||
method: 'PATCH', | ||
method: "PATCH", | ||
headers: { | ||
'Content-Type': 'application/json', | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ ...userData }), | ||
cache: 'no-cache', | ||
}) | ||
cache: "no-cache", | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Error en la respuesta: ${response.status}`) | ||
throw new Error(`Error en la respuesta: ${response.status}`); | ||
} | ||
|
||
if (response.headers.get('Content-Type')?.includes('application/json')) { | ||
const responseData = await response.json() | ||
return responseData | ||
if (response.headers.get("Content-Type")?.includes("application/json")) { | ||
const responseData = await response.json(); | ||
return responseData; | ||
} else { | ||
throw new Error('La respuesta no es un JSON válido.') | ||
throw new Error("La respuesta no es un JSON válido."); | ||
} | ||
} | ||
|
||
//para editar los datos del perfil con la mayoria de los datos | ||
export async function updateUserService(user: UserWithoutId, id: string) { | ||
const url = BASE_URL + '/user/' + id | ||
const url = BASE_URL + "/user/" + id; | ||
|
||
try { | ||
const response = await fetch(url, { | ||
method: 'PATCH', | ||
method: "PATCH", | ||
headers: { | ||
'Content-Type': 'application/json', | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ ...user }), | ||
cache: 'no-cache', | ||
}) | ||
cache: "no-cache", | ||
}); | ||
|
||
return response.json() | ||
return response.json(); | ||
} catch (error) { | ||
console.error('Registration Service Error:', error) | ||
console.error("Registration Service Error:", error); | ||
} | ||
} |