-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { apiUrl } from '../constants/apiUrl.js'; | ||
|
||
export const buscarPergunta = async ({ id }) => { | ||
try { | ||
const response = await fetch(`${apiUrl}/pergunta/${id}`, { | ||
method: 'GET', | ||
}); | ||
|
||
if (!response.ok) { | ||
const err = await response.json(); | ||
console.log(err); | ||
throw new Error(err.errors[0]); | ||
} | ||
|
||
const pergunta = await response.json(); | ||
|
||
return pergunta; | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error(error.message); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { apiUrl } from '../constants/apiUrl.js'; | ||
import { getAuthorization } from '../utils/getAuthorization.js'; | ||
|
||
export const editarPergunta = async ({ id, pergunta, resposta, prioridade }) => { | ||
try { | ||
const response = await fetch(`${apiUrl}/pergunta/${id}`, { | ||
method: 'PATCH', | ||
body: JSON.stringify({ | ||
pergunta, | ||
resposta, | ||
prioridade, | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: await getAuthorization(), | ||
}, | ||
}); | ||
|
||
if (response.status === 403) { | ||
const err = await response.json(); | ||
console.log(err); | ||
throw new Error(err.errors[0]); | ||
} | ||
|
||
if (!response.ok) { | ||
const err = await response.json(); | ||
console.log(err); | ||
throw new Error(err.errors[0]); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error(error.message); | ||
} | ||
}; |
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